If n is a natural number, then find the ending digit of 9^n -5^n.

Answer please…….


Anjali_20
Ms. Chocolaty Girl :p
Saturday, 28 November 2020 10:17 AM

Examples:

Input: N = 136
Output: 123
Explanation: 
 

The numbers formed by repeatedly removing the last digit of 123 are {123, 12, 1}.
Therefore, the sum of these numbers = 123 + 12 + 1 = 136( = N).


Input: N = 107

Output: 98
Explanation:
The numbers formed by repeatedly removing the last digit of 98 are {98, 9}.
Therefore, the sum of these numbers = 98 + 7 = 107( = N).

Approach: The approach is based on the following observations:

  • Consider K = 123.
  • The possible numbers formed from 123 are 1, 12, and 123.
  • Now, 123 can be expressed as 100 + 20 + 3. If all the other numbers are expressed similarly, then the idea is to know the position and frequency of each digit in all the numbers combined, to get the total sum as N