Given a number N, the task is to find a positive number M such that gcd(N^M, N&M) is the maximum possible and M < N. The task is to print the maximum gcd thus obtained.
Input: N = 5 Output: 7 gcd(2^5, 2&5) = 7 Input: N = 15 Output: 5
Approach: There are two cases which need to be solved to get the maximum gcd possible.
- If a minimum of one bit is not set in the number, then M will be a number whose bits are flipped at every position of N. And after that get the maximum gcd.
- If all bits are set, then the answer will the maximum factor of that number except the number itself.
Below is the implementation of the above approach:
- Maximum positive integer divisible by C and is in the range [A, B]
- Count positive integers with 0 as a digit and maximum 'd' digits
- Find maximum number that can be formed using digits of a given number
- Find the maximum number of handshakes
- Find sum of a number and its maximum prime factor
- Find the Number of Maximum Product Quadruples
- Find alphabet in a Matrix which has maximum number of stars around it
- Find a number that divides maximum array elements
- Find maximum power of a number that divides a factorial
- Find the number in a range having maximum product of the digits
- Find integers that divides maximum number of elements of the array
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B
- Minimum positive integer to divide a number such that the result is an odd
- Number of arrays of size N whose elements are positive integers and sum is K
- Querying maximum number of divisors that a number in a given range has
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.
Improved By : Ryuga