Given two numbers n and m. Find the biggest integer a(gcd), such that all integers n, n + 1, n + 2, …, m are divisible by a.
Input : n = 1, m = 2 Output: 1 Explanation: Here, series become 1, 2. So, the greatest no which divides both of them is 1. Input : n = 475, m = 475 Output : 475 Explanation: Here, series has only one term 475. So, greatest no which divides 475 is 475.
Here, We have to examine only two cases:
- if a = b : the segment consists of a single number, hence the answer is a.
- if a < b : we have gcd(n, n + 1, n?+ 2, …, m) = gcd(gcd(n, n + 1), n + 2, …, m) = gcd(1, n + 2, …, n) = 1.
- Minimum elements to be added in a range so that count of elements is divisible by K
- XOR of all the elements in the given range [L, R]
- Number of elements with odd factors in given range
- Number of elements with even factors in the given range
- Queries for GCD of all numbers of an array except elements in a given range
- Count numbers in a range that are divisible by all array elements
- Count elements in the given range which have maximum number of divisors
- Generate a random permutation of elements from range [L, R] (Divide and Conquer)
- Number of Co-prime pairs obtained from the sum of digits of elements in the given range
- Sum of elements in range L-R where first half and second half is filled with odd and even numbers
- Minimum sum of the elements of an array after subtracting smaller elements from larger
- Count of elements whose absolute difference with the sum of all the other elements is greater than k
- Maximize the sum of differences of consecutive elements after removing exactly K elements
- Find elements of array using XOR of consecutive elements
- Generate an array of K elements such that sum of elements is N and the condition a[i] < a[i+1] <= 2*a[i] is met | Set 2
Below is the code for above approach.
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.
Improved By : vt_m