【題解】AtCoder ABC 177C – Sum of product of pairs

【題目敘述】https://atcoder.jp/contests/abc177/tasks/abc177_c

#include <iostream>
using namespace std;

long long n, a, tot, ans, mod = 1e9+7;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        ans += tot*a;
        ans %= mod;
        tot += a;
        tot %= mod;
    }
    cout << ans << "\n";
}

分享本文 Share with friends