Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss10268 - | Accepted | C++11 | 0.020 | 0.000 | 705 | 1 mins ago |
Susgest:
- Use pow default function couldn't AC so we need code Pow binary function
#include <bits/stdc++.h>
#define int long long
using namespace std;
string line1, line2;
long long Pow(long long a, long long b) {
if (!b) return 1;
long long x = Pow(a, b / 2);
if (b % 2 == 0)
return x * x;
else
return x * x * a;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
while(getline(cin, line1)){
getline(cin, line2);
stringstream l1(line1);
stringstream l2(line2);
int x; l1 >> x;
vector<int> a;
int v;
while(l2 >> v) a.push_back(v);
reverse(a.begin(), a.end());
int s = 0;
for(int i=1; i<a.size(); i++)
s += a[i]*i*Pow(x, i-1);
cout<<s<<"\n";
}
}
No comments:
Post a Comment