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

很暴力居然0ms。。。

Posted by lx99410 at 2011-08-21 22:13:10 on Problem 1142
#include<stdio.h>
const int maxn=12000;
int a[maxn],b[maxn],tot;
inline int sell(int x){
       int g=0;
       while(x>0){g+=x%10;x/=10;}
       return g;
}
inline void prime(){
     int i,j,k;
     for(i=2;i<=11000;i++)a[i]=0;
     a[1]=1;
     for(j=1;j<=11000;j++)if(a[j]==0){for(k=2;k<=11000/j;k++)a[j*k]=1;}
     tot=0;
     for(j=1;j<=11000;j++)if(a[j]==0)b[++tot]=j;
}
inline bool check(int x){
     int i;
     if(x==2)return 1;
     for(i=1;i<=tot;i++)
       if(b[i]*b[i]>x)return 1;
       else if(x%b[i]==0)return 0;
}
int main(){
    int n,t,tt,t2,j,i,t1;
    prime();
    while(scanf("%d",&n),n!=0){
      for(i=n+1;;i++){
        if(check(i))continue;
        t=sell(i);tt=i;t2=0;
        for(j=1;j<=tot;j++)
          if(i%b[j]==0){
            t1=sell(b[j]);
            while(tt%b[j]==0){tt/=b[j];t2+=t1;}
            if(t2>t||tt==1)break;
          }
          else if(b[j]*b[j]>tt)break;
        if(tt==1)
          if(t2==t)break;
          else continue;
        if(t2>t)continue;
        if(sell(tt)+t2==t)break;
      }
      printf("%d\n",i);
    }
    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