-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTencent.java
58 lines (54 loc) · 1.21 KB
/
Tencent.java
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
53
54
55
56
57
58
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
* 给出一个整数。。求小于这个整数的质数 之和为这个整数的组数。。包括质数本身*2 这种情况
*/
/**
* @author Iver3on
* @date 2016年9月11日
*/
public class Tencent {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
List<Integer> l = new ArrayList<>();
for(int j = 2; j<m; j++){
if(m(j)){
System.out.print(j+" ");
l.add(j);
}
}
int n = 0;
Collections.sort(l);
for(int i=0,j=l.size()-1;i<=j;){
if(l.get(i)+l.get(j)<m){
i++;
continue;
}
if(l.get(i)+l.get(j)>m){
j--;
continue;
}
if(l.get(i)+l.get(j)==m){
i++;
j--;
n++;
}
}
System.out.println(n);
}
public static boolean m(int num){
for(int j = 2; j<=Math.sqrt(num);j++){
if(num%j == 0){
return false;
}
}
return true;
}
}