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<cstdio> #include<cstring> #include<cmath> int a[100005],b[100005]; int t,m; int dit(int n) { int rel = 0; while(n){ rel += n%10; n/=10; } return rel; } void div(int n) { t = 0; m = (int)sqrt(n*1.0); for(int i =2;i<=m;++i) { if(n%i==0){ a[t] = i; b[t] = 0; while(n%i==0){ ++b[t]; n/=i; } ++t; } } if(n>1){ a[t] = n; b[t++] = 1; } } bool ok(int n)//判断是否都和要求 { int x = dit(n); int y = 0; for(int i = 0;i<t;++i) y += dit(a[i])*b[i]; return x==y; } int main() { int n,i; while(scanf("%d",&n) , n) { for(i=n+1;;++i) { div(i);//分解质因数 if(a[0]!=i && ok(i)) break;//a[0]==i就说明i是一个素数 } printf("%d\n",i); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator