Lost Arithmetic Progression Solution | Codeforces Problem Solution 2022
Long ago, you thought of two finite arithmetic progressions and . Then you found out another sequence containing all elements common to both and . It is not hard to see that is also a finite arithmetic progression. After many years, you forgot what was but remember and . 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 .
Two arithmetic progressions are considered different if they differ in their first term, common difference or number of terms.
It may be possible that there are infinitely many such progressions, in which case you won't even try to look for them! Print 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 .
The first line of input contains a single integer () denoting the number of testcases.
The first line of each testcase contains three integers , and (, , ) denoting the first term, common difference and number of terms of respectively.
The second line of each testcase contains three integers , and (, , ) denoting the first term, common difference and number of terms of respectively.
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 , print .
Otherwise, print the number of finite arithmetic progressions which could be your lost progression modulo . In particular, if there are no such finite arithmetic progressions, print .
Join Now for Solution:-
No comments:
Post a Comment