Problem Description
把一个偶数拆成两个不同素数的和,有几种拆法呢?
Input
输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
Output
对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
Sample Input
30
26
0
Sample Output
3
2
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
ll sushu(ll a)
{
if(a==2) return 1;
if(a<=1||a%2==0) return 0;
ll j=3;
while(j<=(ll)sqrt(a)){
if(a%j==0)
return 0;
j+=2;
}
return 1;
}
int main()
{
int a;
while(scanf("%d",&a)!=EOF&&a)
{
int ans=0;
for(int i=2;i<a/2;i++){
if(sushu(i)==1&&sushu(a-i)==1&&i!=a-i)
ans++;
}
printf("%d\n",ans);
}
return 0;
}
思路要灵活