This is my first own problem created on Polygon! So I am excited!
I request you to try first before reading the tutorial!
You can submit your solution through this invitation link: https://mirror.codeforces.com/contestInvitation/1d814de17ea46b3255e85ecac66b0fd6adcf138d
Problem Name: Arithmetic Geometric Series
time limit per test: 1 second
memory limit per test: 256 megabytes
Problem Description
Salehin has recently learnt about Arithmetic Series (where the difference between 2 consecutive terms remains constant e.g. $$$1+2+3+\ldots +n$$$ Here Constant Difference $$$=2-1=3-2=1$$$) and Geometric Series (where the ratio between 2 consecutive terms remains constant e.g. $$$3+3^2+3^3+\ldots 3^n$$$ Here Constant Ratio $$$=\frac{3^2}{3}=\frac{3^3}{3^2}=3$$$).
Now an idea came to his mind to combine or mashup these 2 series and he named it "Arithmetic Geometric Series"! Arithmetic Geometric Series forms of 2 parameters: $$$x$$$ & $$$n$$$. Arithmetic Geometric Series for $$$x$$$ & $$$n$$$, $$$AG(x,n)=x+2\cdot x^2+3\cdot x^3+4\cdot x^4+\ldots +n\cdot x^n=\sum_{k=1}^{n}{k\cdot x^k}$$$
Salehin wants to determine the values of the series for different values of $$$x$$$ & $$$n$$$. But he is very tired to do such calculations! So he needs your help!
Hence you have to determine the value of $$$AG(x,n)$$$ for given values of $$$x$$$ and $$$n$$$.
Since the answer can be very large, output $$$AG(x,n)$$$ modulo $$$998$$$ $$$244$$$ $$$353$$$.
Input
The first line contains one integer $$$t(1\leq t\leq 10^4)-$$$ the number of test cases. Then $$$t$$$ test cases follows.
Each test case consists of only one line which contains $$$x(0\leq x\leq 10^5)$$$ & $$$n(1\leq n\leq 10^9)-$$$ the parameters of Arithmetic Geometric Series.
Output
For each test case, print one integer $$$-$$$ $$$AG(x,n)$$$ modulo $$$998$$$ $$$244$$$ $$$353$$$.
Example
input
3 5
5 4
4 7
100000 1000000000
0 4
output
1641
2930
145636
110642754
0
Note
In the first test case, $$$AG(3,5)= 3+2\cdot 3^2+3\cdot3^3+4\cdot 3^4+5\cdot3^5=1641$$$
In the second test case, $$$AG(5,4) = 5+2\cdot5^2+3\cdot5^3+4\cdot5^4=2930$$$








You can also use the derivatives to derive the formula quickly.
take the anti derivative of the summation to get a geometric series, plug in the formula, then take the derivative again and plug in x
Nice problem!
Like a few other people here, I added the geometric series of sum(x^i) to get sum((i + 1)x^i) and then used the anti-derivative method. It's kind of a shame that after a page of algebra, your actual code ends up being so short (apart from standard mod power stuff).
358885920