【題解】AtCoder ABC 163D – Sum of Large Numbers

【題目敘述】https://atcoder.jp/contests/abc163/tasks/abc163_d

#include <iostream>
using namespace std;

int n, k, mod = 1e9+7;
long long mn, mx, ans;

int main() {
    cin >> n >> k;
    for (int i = 0; i < k-1; i++){
        mn += i;
        mx += (n-i);
    }
    for (int i = k-1; i <= n; i++){
        mn += i;
        mx += (n-i);
        ans += mx-mn+1;
        ans %= mod;
    }
    cout << ans << "\n";
}

分享本文 Share with friends