Given an integer value n, find out the n-th positive integer whose sum is 10.
Input : n = 2 Output : 27 The first number with sum of digits as 10 is 19. Second number is 27. Input : 15 Output : 154
Method 1 (Simple):
We traverse through all numbers. For every number, we find sum of digits. We stop when we find n-th number with sum of digits as 10.
Method 2 (Efficient):
If we take a closer look, we can notice that all multiples of 9 are present in arithmetic progression 19, 28, 37, 46, 55, 64, 73, 82, 91, 100, 109, ….
However, there are numbers in above series whose sum of digits is not 9, for example, 100. So instead of checking one by one, we start with 19 and increment by 9.
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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Russian Peasant (Multiply two numbers using bitwise operators)
- Smallest number k such that the product of digits of k is equal to n
- Minimum digits to remove to make a number Perfect Square
- Number of Permutations such that no Three Terms forms Increasing Subsequence
- Check if the first and last digit of the smallest number forms a prime
- Print all substring of a number without any conversion
- Complement of a number with any base b
- Check if Decimal representation of an Octal number is divisible by 7
- Program to find Nth term in the series 0, 2, 1, 3, 1, 5, 2, 7, 3,…
- Program to find GCD or HCF of two numbers using Middle School Procedure