Given very large numbers n and x, we need to find the sum of digits of n^x such that :
If n^x < 10 digSum(n^x) = n^x Else digSum(n^x) = Sum(digSum(n^x))
Input : 5 4 Output : 4 We know 54 = 625 Sum of digits in 625 = 6 + 2 + 5 = 13 Sum of digits in 13 = 1 + 3 = 4 Input : 546878 56422 Output : 7
Prerequisite : Recursive sum of digits.
The idea is:
Sum of digits repeats after every 6th exponents.
Let SoD(n) = a
Let b = x % 6
SoD(n^x) = SoD(a^b) except for b = 1 when a = 3 & 6
SoD(n^x) = 9 forall x > 1, when a = 3 & 6
- Find Last Digit of a^b for Large Numbers
- Last digit of Product of two Large or Small numbers (a * b)
- Multiply large integers under large modulo
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find the remainder when First digit of a number is divided by its Last digit
- Largest number less than N with digit sum greater than the digit sum of N
- Count 'd' digit positive integers with 0 as a digit
- Count n digit numbers not having a particular digit
- Check if frequency of each digit is less than the digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- LCM of two large numbers
- Find (a^b)%m where 'b' is very large
- GCD of two numbers when one of them can be very large
- Find (a^b)%m where 'a' is very large
- Sum of two large numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t