GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday, 30 April 2022

Lost Arithmetic Progression Solution | Codeforces Problem Solution 2022

D. Lost Arithmetic Progression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Long ago, you thought of two finite arithmetic progressions A and B. Then you found out another sequence C containing all elements common to both A and B. It is not hard to see that C is also a finite arithmetic progression. After many years, you forgot what A was but remember B and C. You are, for some reason, determined to find this lost arithmetic progression. Before you begin this eternal search, you want to know how many different finite arithmetic progressions exist which can be your lost progression A.

Two arithmetic progressions are considered different if they differ in their first term, common difference or number of terms.

Solution Click Below:- CLICK HERE

It may be possible that there are infinitely many such progressions, in which case you won't even try to look for them! Print 1 in all such cases.

Even if there are finite number of them, the answer might be very large. So, you are only interested to find the answer modulo 109+7.


Input

The first line of input contains a single integer t (1t100) denoting the number of testcases.

The first line of each testcase contains three integers bq and y (109b1091q1092y109) denoting the first term, common difference and number of terms of B respectively.

The second line of each testcase contains three integers cr and z (109c1091r1092z109) denoting the first term, common difference and number of terms of C respectively.

Output

For each testcase, print a single line containing a single integer.

If there are infinitely many finite arithmetic progressions which could be your lost progression A, print 1.

Otherwise, print the number of finite arithmetic progressions which could be your lost progression A modulo 109+7. In particular, if there are no such finite arithmetic progressions, print 0.

Join Now for Solution:- 

                   

No comments:

Post a Comment