Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

2 4 3 1

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

Sample Testcase 2

Testcase Input

2 4 1 3

Testcase Output

-1

Give the python code that passes all the test cases


Step by Step Solution

There are 3 Steps involved in it

Step: 1

To address this question well write a Python program that takes four input values p q x and y The pr... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Computer Engineering questions