3

来源:互联网 发布:知恒这个名字咋样 编辑:程序博客网 时间:2024/04/30 03:35
把一个偶数拆成两个不同素数的和,有几种拆法呢?

Input
输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
Output
对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
Sample Input
30260
Sample Output
32


#include<stdio.h>#include<math.h>int f(int n){    int i;    for(i=2;i<=sqrt((float)n);i++)        if(n%i==0)            return 0;    return 1;}int main(){    int n, i, count;    int a, b;    while (scanf("%d",&n)!=EOF && n){    count=0;        for(i=2;i<n/2;i++){        a=b=0;            a=f(i);            b=f(n-i);            if(a && b)                count++;        }        printf("%d\n",count);}    return 0;}

原创粉丝点击