zoj1133Smith Numbers(3)

来源:互联网 发布:淘宝订单最多保存多久 编辑:程序博客网 时间:2024/06/01 10:14
原来,素数是被排除在定义外啊!!!让你不看题!!!
#include<stdio.h>#include<math.h>int xx(int x){    int sum=0;    while(x!=0)    {       sum+=x%10;               x=x/10;    }      return sum;}int yy(int n){    int i,sum=0,temp,t=n;    for( i = 2; i*i <= n; i++ )        if( n%i == 0 )         {            temp = xx(i);            while( n%i == 0 ){                sum += temp;                n/=i;            }        }    if(t==n)      return -1;    if(n!=1)        sum+=xx(n);    return sum;}   int main(){    int n,x;    while(scanf("%d",&n)&&n)    {       x=n+1;       while(xx(x)!=yy(x))            x++;       printf("%d\n",x);    }    return 0;}       

原创粉丝点击