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 is n plus the sum of the digits of N. (the D stands for digitadition, a term Co Ined by Kaprekar.) For example, D (75) = 75 + 7 + 5 = 87. Given any positive an 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 a, the next number is a + 3 + 3 =, the next is the 3 + 9 = Wuyi, the next is 51 + 5 + 1 = Generate the sequence
33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ...
The number n is called a generator of D (N). In the sequence above, am a generator of a, is a generator of a, Wuyi is a generator of the. Some numbers had more than one generator:for example, 101 had both generators, and 100. A number with no generators is a self-number. There is thirteen self-numbers less than 100:1, 3, 5, 7, 9, (+), 97,,, and.
Write a program to output all positive self-numbers less than or equal 1000000 in increasing order, one per line.
Sample Output
1
3
5
7
9
20
31
42
53
64
|
| <--a lot more numbers
|
9903
9914
9925
9927
9938
9949
9960
9971
9982
9993
|
|
|
By the method of offline calculation, all non-self numbers within 1000000 are calculated, and the number is filtered out and then output from small to large.
1 //UVA 6402#include <stdio.h>3 4 inta[1000001]; 5 6 intMainvoid){7 inti,b,c;8 for(i=0; i<=1000000;++i) {9B=i;c=i;Ten while(c) { Oneb+=c%Ten; AC/=Ten; - } -a[b]=1; the } - for(i=1; i<=1000000;++i) - if(!a[i]) printf ("%d\n", i); - return 0; +}
View Code
Self Numbers C language UVA640