# Arithmetic Progression in CS

In input (through file), there is a positive integer $$N$$. In the following $$N$$ rows, there will be two integers. In $$i ^\text{th}$$ row those will be $$S_i$$ and $$D_i$$.

Each $$S_i$$ belongs to an arithmetic progression $$AP_i$$.

Similarly, each $$D_i$$ represents the common difference of $$AP_i$$.

Answer to the $$i ^\text{th}$$ row is a number $$T_i$$. That number belongs to $$AP_i$$ and is the smallest positive integer of that progression.

Give your answer as $$\displaystyle \sum _{ i = 1 }^{ N }{ T_i }$$.

Details and Assumptions:

• $$N = 5242880$$.

• If $$D_i = 0$$ then $$S_i > 0$$.

• All the numbers (including the final answer) are smaller than $$2^{60}$$.

• 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

×