Given two integers p and q, the task is to find the smallest number K such that K % p = 0 and q % K = 0. If no such K is possible then print -1.
Input: p = 2, q = 8
2 % 2 = 0 and 8 % 2 = 0
Input: p = 5, q = 14
Approach: In order for K to be possible, q must be divisible by p.
- If q % p = 0 then print p
- Else print -1.
Below is the implementation of the above approach:
- Find the smallest number whose digits multiply to a given number n
- Find smallest number n such that n XOR n+1 equals to given k.
- Given a number, find the next smallest palindrome
- Find smallest permutation of given number
- Find the smallest number X such that X! contains at least Y trailing zeros.
- Find the k-th smallest divisor of a natural number N
- Find kth smallest number in range [1, n] when all the odd numbers are deleted
- Find smallest number with given number of digits and sum of digits
- Smallest number by rearranging digits of a given number
- Immediate smallest number after re-arranging the digits of a given number
- Find smallest values of x and y such that ax - by = 0
- Find the smallest twins in given range
- Find k pairs with smallest sums in two arrays | Set 2
- Find the Side of the smallest Square that can contain given 4 Big Squares
- Find the k smallest numbers after deleting given elements
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.