hdu 1333 Smith Numbers

刚开始没看清题意,要找的数一定要是素数

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
int
fun(int n)
{

    int
ans=0;
    while
(n)
    {

        ans+=n%10;
        n/=10;
    }

    return
ans;
}

int
main()
{

    int
n,i,j,k,sum,m;
    while
(scanf("%d",&n)&&n)
    {

        for
(k=n+1;;k++)
        {

            n=k;sum=0;m=0;
            for
(i=2;i<=sqrt(n*1.0);i++)
            {

                while
(n%i==0)
                {

                    m++;
                    sum+=fun(i);
                    n/=i;
                }
            }

            if
(n>1) sum+=fun(n);
            if
(sum==fun(k)&&m)
                break
;
        }

        printf("%d\n",k);
    }

    return
0;
}

你可能感兴趣的:(number)