|
| 1 | +import java.io.*; |
| 2 | +import java.util.*; |
| 3 | +public class JY_1644 { |
| 4 | + |
| 5 | + static int N; |
| 6 | + static List<Integer> pList; |
| 7 | + |
| 8 | + public static void main(String[] args) throws IOException { |
| 9 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + |
| 11 | + N = Integer.parseInt(br.readLine()); |
| 12 | + pList = new ArrayList<>(); |
| 13 | + findPrime(); |
| 14 | + |
| 15 | +// System.out.println(pList); |
| 16 | + |
| 17 | + if(N == 1) { |
| 18 | + System.out.println(0); |
| 19 | + return; |
| 20 | + } |
| 21 | + int s = 0; |
| 22 | + int e = 0; |
| 23 | + int total = pList.get(e); |
| 24 | + int cnt = 0; |
| 25 | + while(s <= e) { |
| 26 | + if(total == N) { |
| 27 | + cnt++; |
| 28 | + total -= pList.get(s); |
| 29 | + s++; |
| 30 | + } |
| 31 | + else if(total > N) { |
| 32 | + total -= pList.get(s); |
| 33 | + s++; |
| 34 | + } |
| 35 | + else { |
| 36 | + e++; |
| 37 | + if(e >= pList.size()) break; |
| 38 | + total += pList.get(e); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + System.out.println(cnt); |
| 43 | + |
| 44 | + } |
| 45 | + public static void findPrime() { |
| 46 | + boolean[] isPrime = new boolean[N+1]; |
| 47 | + Arrays.fill(isPrime, true); |
| 48 | + isPrime[0] = false; |
| 49 | + isPrime[1] = false; |
| 50 | + |
| 51 | + |
| 52 | + for(int i = 2; i <= Math.sqrt(N); i++){ // 2부터 n의 제곱근까지의 모든 수를 확인 |
| 53 | + if(isPrime[i]){ // 해당수가 소수라면, 해당수를 제외한 배수들을 모두 false 처리하기 |
| 54 | + for(int j = i*i; j<= N; j += i){//그 이하의 수는 모두 검사했으므로 i*i부터 시작 |
| 55 | + isPrime[j] = false; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + for(int i=2; i<N+1; i++) { |
| 60 | + if(isPrime[i]) pList.add(i); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments