Created
July 2, 2015 17:47
-
-
Save Learath2/3cd999eeae165813db79 to your computer and use it in GitHub Desktop.
confused
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
discard """ proc createPrimeList(n: Natural): seq[int] = | |
result = @[2] | |
for i in 3..n: | |
for x in result: | |
if i mod x == 0: | |
break | |
else: | |
result.add(i) | |
""" | |
proc isPrime(n: Natural): bool = | |
for i in countup(2, n-1): | |
if n mod i == 0: | |
return false | |
return true | |
proc createPrimeSeq(n: Natural): seq[int64] = | |
result = @[2'i64] | |
for i in 3..n: | |
if isPrime(i): | |
result.add(i) | |
const primes = createPrimeSeq(1000) | |
var | |
num = 600851475143 | |
res = 0 | |
for i in primes: | |
while num mod i == 0: | |
num /= i | |
if num == 0: | |
res = i | |
break | |
echo($res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment