結果

問題 No.278 連続する整数の和(2)
ユーザー rsk0315rsk0315
提出日時 2019-01-11 03:37:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 44,260 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 01:02:30
合計ジャッジ時間 1,237 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <algorithm>

__int128 gcd(__int128 m, __int128 n) {
  while (n) std::swap(m%=n, n);
  return m;
}

int main() {
    intmax_t N;
    scanf("%jd", &N);
    intmax_t M = gcd(N, __int128(N)*(N+1) / 2);
    intmax_t res = 0;
    for (intmax_t i = 1; i*i <= M; ++i) {
        if (M % i == 0) {
            res += i;
            if (i != M / i) res += M / i;
        }
    }
    printf("%jd\n", res);
}
0