-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrime.java
More file actions
52 lines (40 loc) · 1003 Bytes
/
Prime.java
File metadata and controls
52 lines (40 loc) · 1003 Bytes
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
45
46
47
48
49
50
51
52
import java.util.*;
public class Prime
{
static boolean isprime(int x)
{
for (int i=2; i*i<=x; i++)
if (x%i == 0)
return false;
return true;
}
static boolean isSumOfKprimes(int N, int K)
{
if (N < 2*K)
return false;
if (K == 1)
return isprime(N);
if (K == 2)
{
if (N%2 == 0)
return true;
return isprime(N - 2);
}
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();int k;
for(k=1;k<=n;k++)
{
if (isSumOfKprimes (n,k))
{
System.out.print("yes");
}
else
{
System.out.print("No");
}
}
}
}