Given two integers N and X. Make a number in such a way that the number contains the first and last digit occurring in .
Input : N = 10, X = 5 Output : 1010101010 Explanation : 10^1 = 10 10^2 = 100 10^3 = 1000 10^4 = 10000 10^5 = 100000 Take First and Last Digit of each Power to get required number. Input : N = 19, X = 4 Output : 19316911 Explanation : 19^1 = 19 19^2 = 361 19^3 = 6859 19^4 = 130321 Take First and Last Digit of each Power to get required number.
Recommended: Please solve it on “PRACTICE“first, before moving on to the solution.
1. Calculate all Powers of N from 1 to X one by one.
2. Store the Output in power array.
3. Store power i.e, last_digit and power[power_size – 1] i.e, unit_digit from power array to result array.
4. Print the result Array.
Below is the implementation of the above approach :
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.
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Last two digits of powers of 7
- 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
- Balance pans using given weights that are powers of a number
- Minimum number of given powers of 2 required to represent a number
- Minimum number of distinct powers of 2 required to express a given binary number
- Longest subsequence having greater corner values
- Transportation Problem | Set 2 (NorthWest Corner Method)
- Maximize sum of K elements in Array by taking only corner elements
- Check if an Array can be Sorted by picking only the corner Array elements
- Remove k corner elements to maximize remaining sum
- Maximize sum of atmost K elements in array by taking only corner elements | Set 2
- Print powers using Anonymous Function in Python
- Representation of a number in powers of other
- Sum of largest divisible powers of p (a prime number) in a range
- Sum of first N natural numbers by taking powers of 2 as negative number
- Check if a number can be represented as sum of non zero powers of 2
- Number of triangles possible with given lengths of sticks which are powers of 2
- Distinct powers of a number N such that the sum is equal to K
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.