結果

問題 No.888 約数の総和
ユーザー data9824
提出日時 2019-11-30 15:58:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 932 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 68,152 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-11-21 01:22:38
合計ジャッジ時間 13,057 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>

using namespace std;

long long sum(map<long long, long long>::const_iterator itBegin,
              map<long long, long long>::const_iterator itEnd,
              long long base) {
    if (itBegin == itEnd) {
        return base;
    }
    map<long long, long long>::const_iterator itNext = itBegin;
    ++itNext;
    long long result = 0;
    long long powered = 1;
    for (long long i = 0; i <= itBegin->second; ++i) {
        result += sum(itNext, itEnd, base * powered);
        powered *= itBegin->first;
    }
    return result;
}

int main(int argc, const char * argv[]) {
    long long n;
    cin >> n;
    map<long long, long long> factors;
    for (long long divider = 2; divider <= n; ++divider) {
        while (n % divider == 0) {
            ++factors[divider];
            n /= divider;
        }
    }
    cout << sum(factors.begin(), factors.end(), 1) << endl;
    return 0;
}
0