Given three positive integers A, B and C. The task is to find the maximum integer X > 0 such that:
- X % C = 0 and
- X must belong to the range [A, B]
Print -1 if no such number i.e. X exists.
Input: A = 2, B = 4, C = 2 Output: 4 B is itself divisible by C. Input: A = 5, B = 10, C = 4 Output: 8 B is not divisible by C. So maximum multiple of 4(C) smaller than 10(B) is 8
- If B is a multiple of C then B is the required number.
- Else get the maximum multiple of C just lesser than B which is the required answer.
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.
- Generate integer from 1 to 7 with equal probability
- Segment Tree | Set 1 (Sum of given range)
- Find the maximum distance covered using n bikes
- Generate all unique partitions of an integer
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n
- Maximum profit by buying and selling a share at most twice
- Find a pair with maximum product in array of Integers
- Count factorial numbers in a given range
- Square root of an integer
- Find the smallest twins in given range
- Segmented Sieve (Print Primes in a Range)
- Print all Good numbers in given range
- Count 'd' digit positive integers with 0 as a digit
- Count positive integers with 0 as a digit and maximum 'd' digits
- Querying maximum number of divisors that a number in a given range has
- Compute (a*b)%c such that (a%c) * (b%c) can be beyond range
- Maximum profit by buying and selling a share at most k times
- Number of elements with odd factors in given range
- Count maximum points on same line
- Breaking an Integer to get Maximum Product
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.