Engineer bro!
Sun Oct 31 2021 (1 year ago)
Engineer by mistake!
I am a software engineer by passion
You are given two numbers, . You have to find applied times.
(TOC generated by @dsabyte)
Yesterday, puppy Tuzik learned a magically efficient method to find the sum of the integers from to . He denotes it as . But today, like a true explorer, he defined his own new function: , which means the operation sum applied times: the first time to and each subsequent time to the result of the previous operation.
For example, if and , then equals to .
Tuzik wants to calculate some values of the function. Will you help him with that?
The first line contains a single integer T, the number of test cases. Each test case is described by a single line containing two integers D and N.
For each test case, output one integer on a separate line.
2
1 4
2 3
10
21
The problem will be simple if we just have to calculate because from basic mathematics we already know the formula. The Sum of numbers from to is .
Using the above formula, we can find sum of the numbers from to in just time.
But, here we just don't have to calculate , we have to repeat it times.
Let's dry run one of the above examples, .
Iteration | Function call | Numbers | Result |
---|---|---|---|
1 | |||
2 |
Here, we can see that we just need to call native function times with the initial value of .
int main() {
int t;
cin >> t;
while (t--) {
int d, n;
cin >> d >> n;
int ans = n; // initialize and as n
for (int i = 0; i < d; i++) {
ans = (ans * (ans + 1)) / 2;
}
cout << ans << endl;
}
return 0;
}
Time - , per test case
Space -
© 2021 dsabyte. All rights reserved