标签:style blog http color os io for art
Smith Numbers http://poj.org/problem?id=1142 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=133
1 #include<cstdio> 2 int fac[128]; 3 int find_fac(int n){//对n分解质因数,返回质因数个数 4 int cnt=0; 5 for(int i=2;i*i<=n;i+=2){ 6 while(!(n%i)){ 7 n/=i; 8 fac[cnt++]=i; 9 } 10 if(i==2) i--; 11 } 12 if(n>1) fac[cnt++]=n; 13 return cnt; 14 } 15 int div(int x){ 16 int res=0; 17 while(x){ 18 res+=x%10; 19 x/=10; 20 } 21 return res; 22 } 23 bool judge(int n){ 24 int lf=find_fac(n); 25 if(lf==1) return false; 26 int sum=0; 27 for(int i=0;i<lf;i++){ 28 sum+=div(fac[i]); 29 } 30 if(sum==div(n)) return true; 31 return false; 32 } 33 int main(){ 34 int n; 35 while(~scanf("%d",&n),n){ 36 while(!judge(++n)); 37 printf("%d\n",n); 38 } 39 return 0; 40 }
end
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/gaolzzxin/p/3889508.html