Home python Solve the equation in integers: (ax + b) / (cx + d)...

Solve the equation in integers: (ax + b) / (cx + d) = 0

Author

Date

Category

Solve the equation in integers: (ax + b) / (cx + d) = 0

Input format

Enter 4 numbers: a, b, c, d; c and d are not equal to zero at the same time.

Output format

All solutions should be printed if their number is finite, “NO” (without quotes) if there are no solutions, and “INF” (without quotes) if there are infinitely many solutions.

Test 1

Input data:

1
1
2
2

Program output:

NO

Test 2

Input data:

2
-4
7
1

Program output:

2

Help me write Python code


Answer 1, authority 100%

a, b, c, d = int (input ()), int (input ()), int ( input ()), int (input ())
if a == 0 and b == 0:
  print ('INF')
elif a == 0 or b * c == a * d:
  print ('NO')
elif b% a == 0:
  x = -b // a
  print (x)
else:
  print ('NO')

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions