Given a five digit number N. The task is to find the last five digits of the given number raised to the power of 5 after modifying it by arranging the digits as:
first digit, third digit, fifth digit, fourth digit, second digit.
Input : N = 12345 Output : 71232 Explanation : After modification the number becomes 13542. (13542)5 is 455422043125550171232 Input : N = 10000 Output : 00000
Approach : In this problem, just implementation of the actions described in the statement is required. However, there are two catches in this problem.
The first catch is that the fifth power of five-digit number cannot be represented by a 64-bit integer. But we do not actually need the fifth power, we need the fifth power modulo 105. And mod operation can be applied after each multiplication.
The second catch is that you need to output five digits, not the fifth power modulo 105. The difference is when the fifth digit from the end is zero. To output, a number with the leading zero one can either use corresponding formatting (%05d in printf) or extract digits and output them one by one.
Below is the implementation of the above approach :
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Last digit of a number raised to last digit of N factorial
- Print last k digits of a^b (a raised to power b)
- Find the sum of power of bit count raised to the power B
- Find unit digit of x raised to power y
- Number of digits in 2 raised to power n
- K-th digit in 'a' raised to power 'b'
- GCD of a number raised to some power and another number
- Find multiple of x closest to or a ^ b (a raised to power b)
- Find value of y mod (2 raised to power x)
- Check if a number can be expressed as x^y (x raised to power y)
- Minimum removals in a number to be divisible by 10 power raised to K
- Sum of absolute difference of all pairs raised to power K
- Find the remainder when First digit of a number is divided by its Last digit
- Find the first and last M digits from K-th power of N
- Last digit in a power of 2
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Count of N-digit numbers having digit XOR as single 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.