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<math.h> #include<stdio.h> int addall; int add(int n) { int sum=0; while(n!=0) { sum=sum+n%10; n=n/10; } return sum; } int prime(int n) { int i,j; j=(int)sqrt(n)+1; for(i=2;i<j;i++) { if(n%i==0) return 0; } return 1; } int yinzi(int n) { int i=0,j=0,k; k=n; for(i=2;i<sqrt(k)+1;i++) { while(k%i==0) { // printf("%d ",i); n=i; addall=addall+add(i); k=k/i; } } if(k>n) { addall=addall+add(k); } return addall; } int main() { int n,i; while(scanf("%d",&n)) { if(0==n) { break; } for(i=n;;i++) { if(prime(i)) { continue; } addall=0; if(add(i)==yinzi(i)) { printf("%d\n",i); break; } } //printf("%d\n",yinzi(n)); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator