Given four integers a, b, c, d ( upto 10^6 ). The task is to Find the number of solutions for x < y, where a <= x <= b and c <= y <= d and x, y integers.
Input: a = 2, b = 3, c = 3, d = 4 Output: 3 Input: a = 3, b = 5, c = 6, d = 7 Output: 6
Approach: Let’s iterate explicitly over all possible values of x. For one such fixed value of x, the problem reduces to how many values of y are there such that c <= y <= d and x = max(c, x + 1) and y <= d. Let’s assume that c <= d, otherwise, there are no valid values of y of course. It follows, that for a fixed x, there are d – max(c, x+1) + 1 valid values of y because the number of integers in a range [R1, R2] is given by R2 – R1 + 1.
Below is the implementation of the above approach:
- Number of solutions for the equation x + y + z <= n
- Number of solutions of n = x + n ⊕ x
- Number of non-negative integral solutions of a + b + c = n
- Count number of solutions of x^2 = 1 (mod p) in given range
- Number of solutions to Modular Equations
- Find the number of solutions to the given equation
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- Find 'N' number of solutions with the given inequality equations
- Number of integral solutions for equation x = b*(sumofdigits(x)^a)+c
- Number of non-negative integral solutions of sum equation
- Program to find number of solutions in Quadratic Equation
- Find number of solutions of a linear equation of n variables
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Number of N digit integers with weight W
- Find the number of integers from 1 to n which contains digits 0's and 1's only
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.