Given a positive N, the task is to find the last two digits of 7N.
Input: N = 5
The value of 75 = 7 * 7 * 7 * 7 * 7 = 8507
Therefore, the last two digits are 07.
Input: N = 12
The value of 712 = 13841287201
Therefore, the last two digits are 01.
Approach: A general approach to find last K digits of XY is discuss this article in logarithmic time complexity. In this article we will discuss the constant time solution.
Below is the observation for the value of 7N for some values of N:
71 = 7 last two digit = 07
72 = 49 last two digit = 49
73 = 243 last two digit = 43
74 = 2401 lasr two digit = 01
75 = 16807 last two digit = 07
76 = 117649 last two digit = 49
77 = 823543 last two digit = 43
78 = 5764801 last two digit = 01
Based on the above observations we have the following cases:
- If the last two digit in 7N = 07 when N = 4K + 3.
- If the last two digit in 7N = 49 when N = 4K + 2.
- If the last two digit in 7N = 43 when N = 4K + 1.
- If the last two digit in 7N = 01 when N = 4K.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
- Form a number using corner digits of powers
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Program to find last two digits of Nth Fibonacci number
- Program to find last two digits of 2^n
- Find last two digits of sum of N factorials
- Program to find the last two digits of x^y
- Find the last two missing digits of the given phone number
- Find the last two digits of Factorial of a given Number
- Represent n as the sum of exactly k powers of two | Set 2
- Split N powers of 2 into two subsets such that their difference of sum is minimum
- Check if a number can be expressed as sum of two Perfect powers
- Print all integers that are sum of powers of two given numbers
- Last digit of a number raised to last digit of N factorial
- Minimum number of digits to be removed so that no two consecutive digits are same
- Count numbers with same first and last digits
- Print last k digits of a^b (a raised to power b)
- Find first and last digits of a number
- Find last k digits in product of an array 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 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 : grand_master