In input (through file ), there is a positive integer . In the following rows, there will be two integers. In row those will be and .
Each belongs to an arithmetic progression .
Similarly, each represents the common difference of .
Answer to the row is a number . That number belongs to and is the smallest positive integer of that progression.
Give your answer as .
Details and Assumptions :
.
If then .
All the numbers (including the final answer) are smaller than .
The file is "AP1.txt" , textual file "Example.txt" is just an example provided.
For C/C++ solvers, my personal advice is to use fscanf() because it is significantly faster than the ifstream option.
Run time should be about 20 seconds
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Here is my python solution. It turned out, that it is possible to find the values T i in a compact way.