ECJJUN4-Editorial

Problem Link

Author: Soham Chakraborty
Tester: Akash Kumar Bhagat
Editorialist: Soham Chakraborty

DIFFICULTY:

Easy

PREREQUISITES:

Math

PROBLEM:

Finding the n^{th} term of the given pattern

EXPLANATION:

The pattern follows as
1^{st} number 1 time,
2^{nd} number 2 times,
3^{rd} number 3 times,
so to calculate the $n^{th}$term ,if we add natural numbers sequence wise(eg:1+2+3+.... ),
the moment the total sum becomes equal to or greater than the value of n.
The last value added to the sum will be the n^{th} term.

now, we know that summation of n natural numbers is n(n+1)/2.
so if we solve the equation n(n+1)/2=N(input)
we can get the equation.

SOLUTION:

int main() {
int  t;
cin>>t;
while(t--)
{
    long long int i,n;
    cin>>i>>n;
    long long int x=(long long int)(pow((2*n)-0.25,0.5)- 0.5);
    cout<<(((x+i)%1000000007)*((x+i)%1000000007))%1000000007<<endl;
}
}