Self Numbers

Self Numbers

地址http://acm.hdu.edu.cn/showproblem.php?pid=1128

题目大意就是求1000000非d(x)的数字,x是从1到1000000.

比如:

1
3
5
7
9

20

2=1+1;

4=2+2;

6=3+3;

8=4+4;

10=5+5;

11=10+1;

这些都是不用输出的。

解题思路就是枚举从1到1000000所有d(x)的数,然后该数对应的数组为1,默认为0;

其实用bool更好,不过懒得弄,麻烦。

 1 #include<iostream>
 2 using namespace std;
 3 int num[1000005]={0};
 4 int main()
 5 {
 6     int i,j,k,n;
 7     for (i=1,j=1,k=0;i<=1000000;i++,j++){
 8         n=j;
 9         while(j){
10             n+=j%10;
11             j/=10;
12         }
13         k++;
14         num[n]=1;
15     }
16     for (i=1;i<1000000;i++){
17     if (!num[i])
18     printf("%d
",i);
19     }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/sandsideas/p/3652918.html