Given three numbers, our task is to find the largest number by which when given 3 numbers are divided leads to same remainder. It may be assumed that all given numbers are given in increasing order.
Input : a = 62, b = 132, c = 237 Output : 35 35 leads to same remainder 27 when divides 62, 132 and 237. Input : a = 74, b = 272, c = 584 Output : 6
The idea is based on the fact that if a number leaves same remainder with a, b and c, then it would divide their differences. Let us understand assuming that x is our result. Let a = x*d1 + r where r is the remainder when a is divided by x. Similarly we can write b = x*d2 + r and b = x*d3 + r. So the logic is here we first find differences of all three pairs and after that, we find greatest common divisor of differences to maximize result.
Below is the implementation of above idea.
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.
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Program to find remainder when large number is divided by r
- Program to find remainder when large number is divided by 11
- Minimum number of operations on a binary string such that it gives 10^A as remainder when divided by 10^B
- Find the remainder when First digit of a number is divided by its Last digit
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Check if the remainder of N-1 factorial when divided by N is N-1 or not
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Find remainder of array multiplication divided by n
- Count of integers obtained by replacing ? in the given string that give remainder 5 when divided by 13
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Largest N digit number divisible by given three numbers
- Largest Even and Odd N-digit numbers in Octal Number System
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Remainder with 7 for large numbers
- Find numbers that divide X and Y to produce the same remainder
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- Find all the possible numbers in a range that can be evenly divided by its digits
- Find minimum number to be divided to make a number a perfect square
- Program for quotient and remainder of big number
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.