原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=1128
题目大意:
In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence
33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...
题目是想要我们输出1到1000000之中没有的d(x)这样的数;所以我们可以先把这些数找出来,再输出。
题目代码:
1 #include<iostream> 2 int a[10000005]={0}; 3 using namespace std; 4 int main() 5 { 6 int i,j,k,l; 7 for(i=1;i<=1000000;i++) 8 { 9 j=i; 10 l=i; 11 for(;l!=0;) 12 { 13 k=l%10; 14 j+=k; 15 l=l/10; 16 } 17 a[j]=1; 18 } 19 for(i=1;i<=1000000;i++) 20 { 21 if(a[i]!=1) 22 printf("%d ",i); 23 } 24 return 0; 25 }