- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have four numbers a, b, c and d and We have to find number of pairs (x, y) can be found such that that follows the equation: x^2 + y^2 = (x*a) + (y*b) where x in range [1, c] and y in range [1, d]

So, if the input is like a = 2 b = 3 c = 2 d = 4, then the output will be 1 because one pair is (1, 1).

To solve this, we will follow these steps −

- ans := 0
- for x in range 1 to c, do
- l := x*(x-a)
- det2 := b*b - 4*l
- if det2 is same as 0 and b is even and 1 <= floor of (b/2) <= d, then
- ans := ans + 1
- go for next iteration

- if det2 > 0, then
- det := integer part of the square root of det2
- if det^2 is same as det2 and (b+det) is even, then
- if 1 <= floor of (b+det)/2 <= d, then
- ans := ans + 1

- if 1 <= floor of (b-det)/2 <= d, then
- ans := ans + 1

- if 1 <= floor of (b+det)/2 <= d, then

- return ans

Let us see the following implementation to get better understanding −

def solve(a, b, c, d): ans = 0 for x in range(1,c+1): l = x*(x-a) det2 = b*b - 4*l if det2 == 0 and b%2 == 0 and 1 <= b//2 <= d: ans += 1 continue if det2 > 0: det = int(round(det2**0.5)) if det*det == det2 and (b+det) % 2 == 0: if 1 <= (b+det)//2 <= d: ans += 1 if 1 <= (b-det)//2 <= d: ans += 1 return ans a = 2 b = 3 c = 2 d = 4 print(solve(a, b, c, d))

2, 3, 2, 4

1

- Related Questions & Answers
- C/C++ Program for Number of solutions to Modular Equations?
- Program for Number of solutions to Modular Equations in C/C++?
- C/C++ Program for Number of solutions to the Modular Equations?
- Program to find number of solutions in Quadratic Equation in C++
- Program to find number of bit 1 in the given number in Python
- Program to find number of tasks can be finished with given conditions in Python
- Python Program for Number of elements with odd factors in the given range
- Program to find number of unique four indices where they can generate sum less than target from four lists in python
- Find the Number of Solution to Modular Equations using C++
- Program to find last digit of the given sequence for given n in Python
- Python program to find number of days between two given dates
- C program to find Fibonacci series for a given number
- Program to find the sum of all digits of given number in Python
- Program to find coefficients of linear equations that has only one solution in Python
- Program to find number of given operations required to reach Target in Python

Advertisements