class Operator2 {
public static void main(String[] args) {
int n = 30;
int[] arr = GetPrime(n);
for (int i = 0;i<arr.length;i++) {
for (int j = i;j<arr.length;j++) {
if (arr+arr[j] == n) {
System.out.println(n+"="+arr+"+"+arr[j]);
}
}
}
}
//获取小于x的所有质数,并组成数组:
public static int[] GetPrime(int x) {
int number = 0;
int[] prime = {-1};
//获取数组长度:
for (int m = 2;m<=x;m++) {
int i = 2;
do {
if (i == m) {
number++;
//prime = new int[number];
//prime[number-1] = m;
}
i++;
}
while (i<=m && m % (i-1) != 0);
}
prime = new int[number]; //定义一个长度为质数个数的数组
//对数组的元素进行赋值:
number = 0;
for (int m = 2;m<=x;m++) {
int i = 2;
do {
if (i == m) {
number++;
//prime = new int[number];
prime[number-1] = m;
}
i++;
}
while (i<=m && m % (i-1) != 0);
}
return prime;
}
}
|
|