qduoj LC and Prime

来源:互联网 发布:如何使用淘宝购物 编辑:程序博客网 时间:2024/05/05 11:05

LC and Prime

发布时间: 2015年9月19日 21:42   时间限制: 1000ms   内存限制: 32M

Given a number n, please count how many tuple(p1, p2, p3) satisfied that p1<=p2<=p3, p1,p2,p3 are primes and p1 + p2 + p3 = n.

Multiple test cases(less than 100), for each test case, the only line indicates the positive integer n(n≤10000).

For each test case, print the number of ways.

 复制
39
02



#include<stdio.h>#include<math.h>int main(){int p3,n,sum=0; int i,j,p[10010];int num=10010;p[1]=0;for(int i=0;i<=10010;i++)   {    p[i]=i;    }for (int i=2;i<sqrt(num);i++){for(int j=i+1;j<=num;j++) {        if(p[j]!=0&&p[j]%i==0) {    p[j]=0;            }    }}while(scanf("%d",&n)!=EOF){sum=0;if(n>=6){for(i=2;i<=n/3;i++){if(p[i]!=0){for(j=i;j+i<=(n/3)*2;j++){if(p[j]!=0){p3=n-i-j;if(p3>=j&&p[p3]!=0){sum++;}}}}}}printf("%d\n",sum);}return 0;}




0 0
原创粉丝点击