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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print all K digit repeating numbers in a very large number
- Comparing X^Y and Y^X for very large values of X and Y
- Series summation if T(n) is given and n is very large
- GCD of two numbers when one of them can be very large
- Find (a^b)%m where 'a' is very large
- Check whether a very large number of the given form is a multiple of 3.
- Find (a^b)%m where 'b' is very large
- Number of factors of very large number N modulo M where M is any prime number
- How to store a very large number of more than 100 digits in C++
- Count of N-digit numbers having digit XOR as single digit
- Multiply large integers under large modulo
- Largest number less than N with digit sum greater than the digit sum of N
- Find Last Digit of a^b for Large Numbers
- Last digit of Product of two Large or Small numbers (a * b)
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count 'd' digit positive integers with 0 as a digit
- Check if frequency of each digit is less than the digit
- Count n digit numbers not having a particular digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Find the remainder when First digit of a number is divided by its Last digit
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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