Prime and spin-off
Subject description:
To an even split into two distinct primes, there are several demolition law?
Input
Some positive input contains an even number value is not more than 10,000, the number does not exceed 500, the case of 0, ends.
Output
Corresponding to each even output of which is split into different prime number, row for each result.
Sample Input
30 26 0Sample Output
3 2
By the answer:
#include<stdio.h>
#include<math.h>
int is_sushu(int x){ //判断是否为素数
if(x<=0){
return 0;
}
for(int i=2;i<=sqrt(x);i++){ //如果 m 不能被 2 ~ sqrt(m)间任一整数整除,m 必定是素数
if(x%i==0)
return 0;
}
return 1;
}
int main()
{
int m,i,count;
while(~scanf("%d",&m))
{
if(m==0)break; //若遇0,则结束
count=0;
for(i=2;i<=m/2;i++){
if(is_sushu(i)&&is_sushu(m-i)&&m-i!=i){ //m为两个素数之和
count++;
}
}
printf("%d\n",count);
}
return 0;
}