-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1644.py
44 lines (35 loc) · 830 Bytes
/
1644.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 소수의 연속합
import math
N = int(input())
if N == 1:
print(0)
else:
aristo = [True] * (N + 1)
aristo[0] = False
aristo[1] = False
for i in range(2, int(math.sqrt(N) + 1)):
if aristo[i] == True:
j = 2
while (i * j) <= N:
aristo[i * j] = False
j += 1
prime_list = []
for i in range(2, N + 1):
if aristo[i] == True:
prime_list.append(i)
l = 0
r = 0
sum_prime = prime_list[0]
cnt = 0
while l <= r:
if sum_prime > N:
sum_prime -= prime_list[l]
l += 1
else:
if sum_prime == N:
cnt += 1
r += 1
if r == len(prime_list):
break
sum_prime += prime_list[r]
print(cnt)