This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 普通に素数を求める | |
func normal(list []int) { | |
var tmp2 []int | |
var isNotSosuFlg = false | |
// 最大値まで回していき、自分自身以外で割り切れない(約数がない)を求める | |
for j := 0; j < len(list); j++ { | |
// list[0]から始めて自分自身までループし割り切れるか? | |
for k := 0; k < len(list); k++ { | |
if (list[j]%list[k] == 0) && (list[j] != list[k]) { | |
// 自分自身以外で割り切れたら素数ではない | |
isNotSosuFlg = true | |
break | |
} else if list[k] == list[j] { | |
// 上記以外で自分自身は素数 | |
break | |
} | |
} | |
if !isNotSosuFlg { | |
tmp2 = append(tmp2, list[j]) | |
} else { | |
isNotSosuFlg = false | |
} | |
} | |
list = tmp2 // 結果をセット | |
// 素数を表示 | |
//for _, sosu := range list { | |
// fmt.Println(sosu) | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment