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 |
能帮我看一下吗?怎么WA?Source Problem Id:1142 User Id:yeyin Memory:92K Time:250MS Language:C++ Result:Wrong Answer Source #include <iostream.h> #include <memory.h> #include <math.h> long int ss(long int a) { long int s=a; int result=0; int g=int (log(a)/log (10))+1; // cout<<g<<endl; int r=0; for (r=1;r<=g;r++) { result=result+a%10; a=a/10; } // cout<<s<<"result is"<<result<<endl; return result; } void Try (long int r) { long int w=r; long int number[32]; int g=0; memset (number,0,sizeof (number)); long int e=2; while (e<=int (sqrt(r))) { if (r%e==0) { r=r/e; number[g]=e; e=2; g++; } else { e++; } } number[g]=r; int u=0; int result=0; for (u=0;u<=g;u++) { result=result+ss(number[u]); } // cout<<"result"<<result<<endl; if ((result==ss(w))&&(r!=w)) cout<<w<<endl; else Try (w+1); } int main() { long int bignumber=0; cin>>bignumber; while (bignumber!=0) { Try (bignumber); cin>>bignumber; } } W Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator