Given two integers N and X, the task is to find the minimum count of integers with sum N and having unit digit X. If no such representation exists then print -1.
Input: N = 38, X = 9
Minimum two integers are required with unit digit as X to represent as a sum equal to 38.
38 = 19 + 19 or 38 = 29 + 9
Input: N = 6, X = 4
No such representation of
Follow the steps below to solve the problem:
- Obtain the unit digit of N and check if it achieved by the sum of numbers whose unit digits are X.
- If it is possible, check if N ? X * ( Minimum number of times a number with unit digit X needs to be added to get sum N).
- If the above condition is satisfied then print the minimum number of times a number with unit digit X needs to be added to get sum N. Otherwise, print -1.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
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 N-digit numbers having digit XOR as single digit
- Maximum and minimum sums from two numbers with digit replacements
- Count numbers with unit digit k in given range
- Count n digit numbers not having a particular digit
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find unit digit of x raised to power y
- Find the unit place digit of sum of N factorials
- Sum of integers upto N with given unit digit
- Sum of integers upto N with given unit digit (Set 2)
- Queries on sum of odd number digit sums of all the factors of a number
- Minimize number of cuts required to break N length stick into N unit length sticks
- Count of minimum reductions required to get the required sum K
- Split first N natural numbers into two sets with minimum absolute difference of their sums
- Split squares of first N natural numbers into two sets with minimum absolute difference of their sums
- Count 'd' digit positive integers with 0 as a digit
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Minimum length of subsequence having unit GCD
- Generate a combination of minimum coins that sums to a given value
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.