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 :
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count of numbers whose sum of increasing powers of digits is equal to the number itself
- Last two digits of powers of 7
- Minimum number of given powers of 2 required to represent a number
- Finding powers of any number P in N!
- Representation of a number in powers of other
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Distinct powers of a number N such that the sum is equal to K
- Find all powers of 2 less than or equal to a given 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
- Balance pans using given weights that are powers of a number
- Sum of first N natural numbers by taking powers of 2 as negative number
- Sum of largest divisible powers of p (a prime number) in a range
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Find the Largest number with given number of digits and sum of digits
- Find the average of k digits from the beginning and l digits from the end of the given number
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.
Improved By : manishshaw1