Reciprocal sum

2.9

17 votes
Very-Easy
Problem

Rishab likes AP sequences very much. If we are given the initial term (say a) and the common difference (say d), we can generate the whole sequence such that the sequence is a, a+d, a+2d.....and so on.

Since Rishab likes AP too much, he generated his own sequence containing infinite number of terms using a and d. Your task is to compute the following summation , given the values of a and d. Since the answer may be large, output the answer modulo 10^9 + 7.

enter image description here

INPUT

The first input will be an integer t denoting the number of test cases. In the next t lines, there will be given two integers a and d (as shown in the formula above) in each line separated with a space.

OUTPUT

For each test case t, you have to print only one integral value per line, that is the answer to the question.

CONSTRAINTS

1<=t<=10^6

1<=a<=10^18

0<=d<=10^18

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The value of a=1 and d=0. Therefore, all the terms in the sequence are 1. Therefore, their summation uptil infinite terms will be infinity. Thus, its answer will be 0.

Editor Image

?