Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我了个去,终于AC了

Posted by 201501060326 at 2016-03-27 00:49:37 on Problem 1142
#include <iostream>
using namespace std;
int prime[12000],f[12000];
int tot;
int get_prime()
{
    f[1]=1;
    int i,j;
    for(i=2; i<=11000; i++)
    {
        if(f[i]==0)
        {
            for(j=2; j<=11000/i; j++)
            {
                f[i*j]=1;
            }
        }
    }
    for(i=1,tot=0; i<=11000; i++)
    {
        if(f[i]==0)
            prime[++tot]=i;
    }
    return 0;
}
bool is_prime(int num)
{
    int i;
    if(num==2)
        return true;
    for(i=1; i<=tot; i++)
    {
        if(prime[i]*prime[i]>num)
            return true;
        else if(num%prime[i]==0)
            return false;
    }
}
int digit(int num)
{
    int sum=0;
    while(num)
    {
        sum+=num%10;
        num/=10;
    }
    return sum;
}
int main()
{
    int k,i,j,t,sum_1,sum_2;
    get_prime();
    while(cin>>k&&k!=0)
    {
        for(i=k+1;; i++)
        {
            t=i;
            sum_1=0;
            sum_2=digit(t);
            if(is_prime(t))
                continue;
            for(j=1; j<=tot&&t!=1; j++)
            {
                if(t%prime[j]==0)
                {
                    sum_1+=digit(prime[j]);
                    t/=prime[j];
                    j--;
                }
            }
            if(t!=1)
                sum_1+=digit(t);
            if(sum_2==sum_1)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator