Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Ator Ali's Income

By shajia · Limits 1s, 512 MB

Ator Ali loves to make money. He does not care whether his source of income is good or evil. As his intention is not clear, he can not find any honest way to make the money. As a result, all his income sources are illegal.

Ator Ali doesn't know that a group is secretly observing his income pattern and they are keeping track of it. The group has set a penalty amount against his monthly income. When the right time comes, they will send him a legal notice and demand the penalty amount from him. After a few months, their analyst figured that Ator Ali's income increases by dd after every month. So there is no need to store the exact income of Ator Ali after each month. Instead, his income after any month nn can be calculated from his first month’s income and the value of dd. As there are many dishonest persons in society, the group is busy keeping track of the income of a lot of people. So they need your help to calculate the income of Ator after the nthnth month.


The first line of the input will contain an integer TT (1T1000)(1 \leq T \leq 1000) that denotes the number of test cases. Then for each test case there will be an integer QQ (1Q500)(1 \leq Q \leq 500) which denotes the number of queries we want to make. Then for each query, there will be three positive integers xx, dd, nn ( 0x,d,n1090 ≤ x, d, n ≤ 10^9) that denotes Ator Ali's income of the first month from when the group started tracking his income, the increased amount of income between any two consecutive months and the month on which they want to calculate Ator Ali’s income respectively.


For each input, output the amount of money earned by Ator Ali on the n-th month.


10 5 6



93% Solution Ratio

Siddik_53rdEarliest, 6M ago

TurinhstuFastest, 0.1s

plasticneuronsLightest, 10 MB

anonyo.akandShortest, 168B


Login to submit


To solve this problem, the main task is to calculate the income of Ator in any month. As we know the...

Toph uses cookies. By continuing you agree to our Cookie Policy.