結果

問題 No.278 連続する整数の和(2)
ユーザー xuzijian629xuzijian629
提出日時 2018-11-02 23:37:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 461 bytes
コンパイル時間 3,107 ms
コンパイル使用メモリ 198,756 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 23:18:37
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 13 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 15 ms
4,384 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    i64 n;
    i64 ret = 0;
    cin >> n;

    __int128_t s = __int128_t(n) * (n + 1) / 2;
    i64 g = __gcd(s, __int128_t(n));

    for (i64 i = 1; i * i <= g; i++) {
        if (g % i == 0) {
            ret += i;
            if (i != g / i) {
                ret += g / i;
            }
        }
    }
    cout << ret << endl;
}
0