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:
- Count of alphabets whose ASCII values can be formed with the digits of N
- Count of non decreasing arrays of length N formed with values in range L to R
- Range Queries to count the number of even parity values with updates
- Number of values of b such that a = b + (a^b)
- Default values in a Map in C++ STL
- Find N values of X1, X2, ... Xn such that X1 < X2 < ... < XN and sin(X1) < sin(X2) < ... < sin(XN)
- Find minimum possible values of A, B and C when two of the (A + B), (A + C) and (B + C) are given
- Find the values of X and Y in the Given Equations
- Comparing X^Y and Y^X for very large values of X and Y
- Find smallest values of x and y such that ax - by = 0
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Sum of even values and update queries on an array
- Eigenspace and Eigenspectrum Values in a Matrix
- Sum of all natural numbers from L to R ( for large values of L and R )
- Sum of values of all possible non-empty subsets of the given array
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.