結果

問題 No.278 連続する整数の和(2)
ユーザー uenokuuenoku
提出日時 2017-01-08 00:05:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 862 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 67,928 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-08-22 16:52:34
合計ジャッジ時間 4,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
/*
 * 係数がわかれば良い
 * sum suc(n) = (nx+n(n+1)/2)
 */
lli gcd(lli A, lli B)
{
    if (B > A)
        swap(A, B);
    if (A % B == 0)
        return B;
    else
        return gcd(B, A % B);
}
lli sum_of_yakusuu(lli N)
{
    lli ans = 0;
    lli cnt = 1;
    while (cnt * cnt <= N) {
        if (N % cnt == 0)
            ans += cnt + N / cnt;
        if (N == cnt * cnt) {
            ans -= cnt;
        }
        cnt++;
    }
    return ans;
}

int main()
{
    lli n;
    cin >> n;
    cout << sum_of_yakusuu(gcd(n, (n & 1 ? (n + 1) / 2 * n : n / 2 * (n + 1)))) << endl;
}
0