Goldbach's theorem ... All even numbers can be represented by the sum of prime numbers. Let's write this theorem in java.
public class Qiita {
public static void main(String[] args) {
boolean bl=true;
int num=0;
int n=6;
String ans="";
int[] sosuu=new int[24];
for(int i=3; i<=100; i++) {
for(int j=2; j<=(i/2); j++) {
if(i%j==0){
bl=false;
}
}
if(bl==true){
sosuu[num]=i;
num++;
}else{
bl=true;
}
}
while(n<=100) {
for(int i=0; i<24; i++) {
for(int j=0; j<24; j++) {
if(n==(sosuu[i]+sosuu[j]) &&i<=j) {
ans+="["+sosuu[i]+","+sosuu[j]+"]";
}
}
}
System.out.print(n+"\t"+":"+ans);
ans="";
System.out.println();
n+=2;
}
}
}
I used too much for and the program got dirty, but I managed to complete it.
Recommended Posts