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 |
我了个去,终于AC了#include <iostream> using namespace std; int prime[12000],f[12000]; int tot; int get_prime() { f[1]=1; int i,j; for(i=2; i<=11000; i++) { if(f[i]==0) { for(j=2; j<=11000/i; j++) { f[i*j]=1; } } } for(i=1,tot=0; i<=11000; i++) { if(f[i]==0) prime[++tot]=i; } return 0; } bool is_prime(int num) { int i; if(num==2) return true; for(i=1; i<=tot; i++) { if(prime[i]*prime[i]>num) return true; else if(num%prime[i]==0) return false; } } int digit(int num) { int sum=0; while(num) { sum+=num%10; num/=10; } return sum; } int main() { int k,i,j,t,sum_1,sum_2; get_prime(); while(cin>>k&&k!=0) { for(i=k+1;; i++) { t=i; sum_1=0; sum_2=digit(t); if(is_prime(t)) continue; for(j=1; j<=tot&&t!=1; j++) { if(t%prime[j]==0) { sum_1+=digit(prime[j]); t/=prime[j]; j--; } } if(t!=1) sum_1+=digit(t); if(sum_2==sum_1) { cout<<i<<endl; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator