結果

問題 No.1252 数字根D
ユーザー MisterMister
提出日時 2020-10-09 21:38:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 72,900 KB
最終ジャッジ日時 2025-01-15 04:11:49
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

lint calc(lint n, lint d) {
    if (n <= 0) return 0;
    --d;
    lint block = n / d;
    n -= block * d;
    return d * (d + 1) / 2 * block + n * (n + 1) / 2;
}

void solve() {
    lint d, a, b;
    std::cin >> d >> a >> b;
    std::cout << calc(b, d) - calc(a - 1, d) << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}
0