Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大家帮我看看这个代码 为什么会超时呢??#include<stdio.h> #include<math.h> int prime(int x,int a[]) { int i,j,flag,k=0; for(i=2;i<=x;i++) { flag=1; for(j=2;j<=sqrt(i);j++) { if(i%j==0) { flag=0;break; } } if(flag) { a[k]=i;k++; } } return k; } int count(int x) { int a[170],sum[170]; int i,j,done=0; int n=prime(x,a); for(i=0;i<n;i++) { sum[i]=0; for(j=i;(j<n)&&(sum[i]<x);j++) { sum[i]=sum[i]+a[j]; if(sum[i]==x) { done++; break; } } } return done; } main() { int t[10],i=0; int x,j; while(x) { scanf("%d",&x); t[i]=count(x);i++; } for(j=0;j<i-1;j++) { printf("%d\n",t[j]); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator