forked from paulot/uva2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path927.cpp
More file actions
41 lines (32 loc) · 642 Bytes
/
Copy path927.cpp
File metadata and controls
41 lines (32 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int poly[30], tc, pn, d, k, in;
ll power(int n, int p) {
ll ans = 1;
for (int i = 0; i < p; i++) ans *= n;
return ans;
}
ll calc(int n) {
ll ans = 0;
for (int i = 0; i < pn; i++) ans += poly[i] * power(n, i);
return ans;
}
int main() {
cin >> tc;
while (tc--) {
cin >> pn; pn++;
for (int i = 0; i < pn; i++) cin >> poly[i];
cin >> d >> k;
unsigned long long ck = 0;
for (int n = 1; n <= k; n++) {
ck += n * d;
if (ck >= k) {
cout << calc(n) << endl;
break;
}
}
}
return 0;
}