This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void fastIO() {
ios_base::sync_with_stdio(false), cin.tie(0);
}
#define int long long
const int MOD = 1e9 + 7;
const int MAXN = 10001;
int N;
int vals[MAXN];
int ans = 0;
long long modular(long long base, long long exp, int mod) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1)
res= (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
signed main() {
fastIO();
cin >> N;
for (int i = 0; i < N; i++) {
cin >> vals[i];
}
reverse(vals, vals + N);
for (int i = 0; i < N; i++) {
ans += ((vals[i] - 1) * modular(N, i, MOD)) % MOD;
ans %= MOD;
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |