Sum of digits of a number raised to the power k
C++
Medium
math
Task «Sum of digits of a number raised to the power k»
Given a natural number n and a natural number k. Raise n to the power of k, then find the sum of the digits of the resulting number. If the sum of the digits is greater than 9, repeat the process until a single-digit number is obtained. Output this single-digit number.
Input Format
In the first line, an integer n (1 ≤ n ≤ 10^9). In the second line, an integer k (1 ≤ k ≤ 10^9).
Output Format
One integer — the result of repeatedly summing the digits of the number n^k.
Examples
Example 1
INPUT
3
Circle 5
Rectangle 4 6
Triangle 3 4
OUTPUT
Invalid input
Example 2
INPUT
2 3
1 2 3
4 5 6
OUTPUT
8
Example 3
INPUT
5
2
OUTPUT
7
Example 4
INPUT
1
Circle 1
OUTPUT
Invalid input
main.cpp