Given three integers N, K and L. The task is to find the average of the first K digits and the last L digits of the given number N without any digit overlapping.
Input: N = 123456, K = 2, L = 3
Sum of first K digits will be 1 + 2 = 3
Sum of last L digits will be 4 + 5 + 6 = 15
Average = (3 + 15) / (2 + 3) = 18 / 5 = 3
Input: N = 456966, K = 1, L = 1
Approach: If the count of digits in n is less than (K + L) then it isn’t possible to find the average without digits overlapping and print -1 in that case. If that’s not the case, find the sum of the last L digits of N and store it in a variable say sum1 then find the sum of the first K digits of N and store it in sum2. Now, print the average as (sum1 + sum2) / (K + L).
Below is the implementation of the above approach:
- Find the Largest number with given number of digits and sum of digits
- 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
- Check if the sum of digits of number is divisible by all of its digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Sum of the digits of square of the given number which has only 1's as its digits
- Find first and last digits of a number
- Given a number n, find the first k digits of n^n
- Find a number x such that sum of x and its digits is equal to given n.
- Find next greater number with same set of digits
- Find the total Number of Digits in (N!)N
- Find the sum of digits of a number at even and odd places
- Find a Number X whose sum with its digits is equal to N
- Find N digits number which is divisible by D
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.