There are multiple methods for this question;
First:
Because AB * AB = (10 * A + B) * (10 * A + B) = 100 * a * A + 10*2 * a * B + B * B = A * A + 2 * a * B + B * B = (a + B) * (A + B)
ABC * abc = (100 * A + 10 * B + C) * (100 * A + 10 * B + C)
= 10000 * a * A + 2000 * a * B + 100 * B + 200 * a * C + 20 * B * C + C * C
= A * A + 2 * a * B + B * B + 2 * a * C + 2 * B * C + C * C
= (A + B) ^ 2 + 2 * C * (a + B) + C * C
= (A + B + C) * (A + B + C)
Similarly, we can know that the four-digit and five-digit numbers are the same,
That is, N x n is equal to N x n.
# Include <stdio. h>
# Include <string. h>
Int fun (int K)
{
If (k <10)
Return K;
Int ans = 0;
While (k> 0)
{
Ans = ans + K % 10;
K = K/10;
}
Return fun (ANS );
}
Int main ()
{
Int m, n, I;
While (scanf ("% d", & M), m)
{
Int ans = 1;
N = fun (m );
While (M --)
{
Ans = ans * N;
If (ANS> 9)
Ans = fun (ANS );
}
Printf ("% d \ n", ANS );
}
Return 0;
}
Method 2:
The calculation method is: the root of the number is equal to the remainder of the original number divided by 9. Therefore, this calculation process is often called the "9-in-9" method ". For example, 39/9 = 3. True (for the root of a single number)
Same theorem: If two products are divided by the remainder of M, they are divided by the remainder of M. For example: 7% 3 = 1 5% 3 = 2 7*5/3 = 2 = 1*2 (for the product of two numbers, calculate the root)
In number theory, there is a conclusion: "The nine-remainder number of the product of a number is equal to the product of the Nine-remainder number." When the remainder is 0, this number is nine.
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Int m, I;
While (scanf ("% d", & M), m)
{
Int ans = 1;
For (I = 1; I <= m; I ++)
Ans = ans * m % 9;
If (ANS = 0)
Printf ("9 \ n ");
Else
Printf ("% d \ n", ANS );
}
Return 0;
}