Given two integers N and K, the task is to print the number formed by adding product of its max and min digit, K times.
Input: N = 14, K = 3
M(1)=14 + 1*4 = 18
M(2)=18 + 1*8 = 26
Input: N = 487, K = 100000000
- A natural intuition is to run a loop K times and keep updating the value of N.
- But one observation can be observed that after some iteration minimum value of digit may be zero and after that N is never going to be updated because:
M(N + 1) = M(N) + 0*(max_digit)
M(N + 1) = M(N)
- Hence we just need to figure out when minimum digit became 0.
Below is the C++ implementation of the above approach:
Time Complexity: O(K)
Auxillary Space: O(1)
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Find minimum possible digit sum after adding a number d
- Number formed after K times repeated addition of smallest divisor of N
- Convert a number of length N such that it contains any one digit at least 'K' times
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Maximum number with same digit factorial product
- Check if the product of digit sum and its reverse equals the number or not
- Maximum of sum and product of digits until number is reduced to a single digit
- Check whether a number can be expressed as a product of single digit numbers
- Sum of all numbers formed having 4 atmost X times, 5 atmost Y times and 6 atmost Z times
- GCD of two numbers formed by n repeating x and y times
- N digit numbers divisible by 5 formed from the M digits
- Count numbers formed by given two digit with sum having given digits
- Smallest integer greater than n such that it consists of digit m exactly k times
- Count of Numbers in a Range where digit d occurs exactly K times
- Sum of all N digit palindromic numbers divisible by 9 formed using digits 1 to 9
- Sum of product of all subsets formed by only divisors of N
- Product of all Subsets of a set formed by first N natural numbers
- Sum of series formed by difference between product and sum of N natural 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 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.