Calculates the number of compliant rules.
Given the sum of the Functions d (n) = N + n, n is a positive integer, for example, D (78) = 78 + 7 + 8 = 93. In this way, this function can be regarded as a generator, for example, 93 can be regarded as generated by 78.
Define number A: Number A cannot find a number B can be created by D (B) = A, that is, a cannot be generated by other numbers. Now we need to write a program to find all the qualified numbers defined by a in 1 to 10000.
Output:
1
3
...
# Include <iostream>
Using namespace STD;
Int D (int I)
{
Int J = I;
Int sum = 0;
While (I! = 0)
{
Sum + = I % 10;
I/= 10;
}
Sum = sum + J;
// Cout <"sum =" <sum <Endl;
Return sum;
}
Int main ()
{
For (INT I = 1; I <10000; I ++)
{
For (Int J = 1; j <10000; j ++)
{
If (I! = D (j) & J <I)
Continue;
If (I = D (j ))
Break;
Else
{
Cout <I <Endl;
// System ("pause ");
Break;
}
}
}
Return 0;
}