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 |
小弟愚笨,不会打表。。。++!!用了750Ms,,,,,大牛看看可以改进不?#include<iostream> #include<cmath> #include<time.h> using namespace std; int main() { int n,a,j,i,t,p; while(cin>>a) { n=0; if(a==0) break; for(j=2;j<=sqrt((double)a);j++) { if(a%j==0) break; } if(j>sqrt((double)a)) { n++; } for(p=2;p<=a/2;p++) { t=0; for(i=p;i<=a;i++) { for(j=2;j<=sqrt((double)p);j++) { if(p%j==0) break; } if(j<=sqrt((double)p)) break; for(j=2;j<=sqrt((double)i);j++) { if(i%j==0) break; } if(j>sqrt((double)i)) { t+=i; if(t>a) break; if(t==a) { n++; break; } } } } cout<<n<<endl; printf("%u secs.\n",clock()/CLOCKS_PER_SEC); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator