#include "stdio.h"
/*#include "time.h"*/
const int MAXINT=1000000;
int count=0;
int Make(int x){
int temp=x;
while(x>0){
temp=temp+x%10;
x=x/10;
count++;
}
return temp;
}
int main(){
unsigned char is_self_number[1000010];
int i,j,k,p=1;
/* double t1,t2;
t1=clock();*/
for(i=1;i<=MAXINT;i++)is_self_number[i]=1;
while(p<=MAXINT){
while(!is_self_number[p])p++;
k=p;
while((k=Make(k))<=MAXINT){
if(is_self_number[k]==0)break;
is_self_number[k]=0;
}
p++;
}
for(i=1;i<=MAXINT;i++)
if(is_self_number[i])printf("%d\n",i);
/*t2=clock();
printf("Total time=%5.4lf\n",(t2-t1)/CLOCKS_PER_SEC);
printf("Make %d Times.\n",count);*/
return 0;
}
纯水题。暴力枚举就可以了。同时要注意剪枝(第24行)