分拆素数和
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 28706 Accepted Submission(s): 12479
Total Submission(s): 28706 Accepted Submission(s): 12479
Problem Description
把一个偶数拆成两个不同素数的和,有几种拆法呢?
Input
输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
Output
对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
Sample Input
30 26 0
Sample Output
3 2
Source
Recommend
lcy | We have carefully selected several similar problems for you: 2099 1262 1431 2097 2096
#include<stdio.h> #include<math.h> int sushu(int n) { int i; for(i=2;i<=sqrt(n);i++) { if(n%i==0) return 0; } return 1; } int main() { int m,n,i,num=0; while(scanf("%d",&n),n) { num=0; for(i=3;i<n/2;i+=2) { m=n-i; if(sushu(i)&&sushu(m)) num++; } printf("%d ",num); } return 0; }