Problem Description
把一个偶数拆成两个不同素数的和,有几种拆法呢?
Input
输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
Output
对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
Sample Input
30
26
0
Sample Output
3
2
#include <iostream>
#include <math.h>
using namespace std;
int s(int n)
{
if(n==2||n==3)/
return 1;
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
int m;
while(cin>>m&&m!=0)
{
int a=0;
for(int j=2; j<m/2; j++)/
{
if(s(j)&&s(m-j))//只有都是1的时候才算
{
a++;
}
}
cout<<a<<endl;
}
return 0;
}