Question: Your Question is : Problem Statement Given four positive integers p, q, x, and y, you can perform an operation that increases both x and

Your Question is : Problem Statement

Given four positive integers p, q, x, and y, you can perform an operation that increases both x and y by 1 simultaneously.

123456

6

7

9

18

11

12

Your task is to determine the number of operations needed to meet the condition where px equals qy.

Input Format

The first Line contains 4 space-separated integers p, q, x and y

Output Format

A single integer represents the total number of operations.

If the answer is not possible by any number of operations then print -1.

| Constraints

1>= p, q, x and y <= 100000.

Sample Testcase 1

Testcase Input
2431

Testcase Output

1

Explanation

Value of p,q,x,y is 2,4,3,1 if we add 1 to x and y then x will become 4 and y will become 2 so the answer will be 1 as:

p*x=2*4 = 8

qy=4-28

p*x=q*y=8 which satisfies the condition

111

Sample Testcase 2

Testcase Input

2413

Testcase Output

-1
Give the python code that passes all the test cases


Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Given the problem statement and the requirement for a Python code solution lets analyze the goal and how to achieve it before writing the code Objecti... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Engineering Questions!