-
-
Save inoryy/173fb2ae5a67790a1b2a to your computer and use it in GitHub Desktop.
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
def sieve(n): | |
is_prime = [True] * n | |
primes = [] | |
for i in range(2, n): | |
if is_prime[i]: | |
primes.append(i) | |
for j in range(2 * i, n, i): | |
is_prime[j] = False | |
return primes | |
n = 1000 | |
res = [0] * n | |
res[0] = 1 | |
primes = sieve(n) | |
for p in primes: | |
for i in range(0, n): | |
if i + p < n: | |
res[i + p] += res[i] | |
for i in range(0, n): | |
if res[i] > 5000: | |
print(i) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment