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 the Number of Maximum Product Quadruples
- Find sum of a number and its maximum prime factor
- Find the number in a range having maximum product of the digits
- Find a number that divides maximum array elements
- Find maximum power of a number that divides a factorial
- Find alphabet in a Matrix which has maximum number of stars around it
- 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
- Number of arrays of size N whose elements are positive integers and sum is K
- Minimum positive integer to divide a number such that the result is an odd
- Querying maximum number of divisors that a number in a given range has