Given two integers A and B. The task is to find the count of all possible values X such that A % X = B. If there are infinite number of possible values then print -1.
Input: A = 21, B = 5
8 and 16 are the only valid values for X.
Input: A = 5, B = 5
X can have any value > 5
Approach: There are three possible cases:
- If A < B then no value of X can satisfy the given condition.
- If A = B then infinite solutions are possible. So, print -1 as X can be any value greater than A.
- If A > B then the number of divisors of (A – B) which are greater than B is the required count.
Below is the implementation of the above approach:
- All possible values of floor(N/K) for all values of K
- Count possible values of K such that X - 1 and Y - 1 modulo K is same
- Count of all values of N in [L, R] such that count of primes upto N is also prime
- Possible values of Q such that, for any value of R, their product is equal to X times their sum
- Largest subsequence such that all indices and all values are multiples individually
- Minimum possible value T such that at most D Partitions of the Array having at most sum T is possible
- Count of all possible Paths in a Tree such that Node X does not appear before Node Y
- Sum of values of all possible non-empty subsets of the given array
- Product of values of all possible non-empty subsets of given Array
- Probability of getting all possible values on throwing N dices
- Choose an integer K such that maximum of the xor values of K with all Array elements is minimized
- Minimum LCM and GCD possible among all possible sub-arrays
- Partitions possible such that the minimum element divides all the other elements of the partition
- Minimum possible sum of array B such that AiBi = AjBj for all 1 ≤ i < j ≤ N
- Count of distinct possible pairs such that the element from A is greater than the element from B
- Count the number of ways to give ranks for N students such that same ranks are possible
- Count possible splits of sum N into K integers such that the minimum is at least P
- Possible to form a triangle from array values
- Check if it is possible to make two martices strictly increasing by swapping corresponding values only
- Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given
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.