标签:style class blog c code tar
1 //Accepted 620 KB 15 ms 2 //wa1 MAXN 太小了一开始用的10005; 3 //wa2 没判断素数 4 //wa3 分解质因子用的小于n 5 #include <cstdio> 6 #include <cstring> 7 const int MAXN = 100005; 8 int pri[MAXN]; 9 int cnt; 10 void prime() 11 { 12 for (int i=2;i<MAXN;i++) 13 if (!pri[i]) 14 { 15 if ((long long )i*i<(long long )MAXN) 16 for (int j=i*i;j<MAXN;j+=i) 17 pri[j]=1; 18 } 19 cnt=0; 20 for (int i=2;i<MAXN;i++) 21 { 22 if (!pri[i]) 23 { 24 pri[cnt++]=i; 25 } 26 } 27 } 28 int getsumn(int n) 29 { 30 int ans=0; 31 while (n>0) 32 { 33 ans+=n%10; 34 n/=10; 35 } 36 return ans; 37 } 38 int judge(int n) 39 { 40 int i=0; 41 int temp=getsumn(n); 42 int sum=0; 43 int flag=0; 44 while (pri[i]*pri[i]<=n) 45 { 46 if (n%pri[i]==0) 47 { 48 flag=1; 49 while (n%pri[i]==0) 50 { 51 sum+=getsumn(pri[i]); 52 n/=pri[i]; 53 } 54 } 55 i++; 56 } 57 if (flag==0) return 0; 58 if (n!=1) 59 { 60 sum+=getsumn(n); 61 } 62 if (temp==sum) return 1; 63 return 0; 64 } 65 void slove(int n) 66 { 67 n++; 68 while (judge(n)==0) 69 { 70 n++; 71 } 72 printf("%d\n",n); 73 } 74 int n; 75 int main() 76 { 77 prime(); 78 while (scanf("%d",&n),n) 79 { 80 slove(n); 81 } 82 return 0; 83 }
poj1142Smith Numbers,布布扣,bubuko.com
标签:style class blog c code tar
原文地址:http://www.cnblogs.com/djingjing/p/3750935.html