結果
問題 | No.888 約数の総和 |
ユーザー |
![]() |
提出日時 | 2019-11-30 16:01:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 988 bytes |
コンパイル時間 | 809 ms |
コンパイル使用メモリ | 67,348 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 01:22:41 |
合計ジャッジ時間 | 2,048 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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 * divider <= n; ++divider) { while (n % divider == 0) { ++factors[divider]; n /= divider; } } if (n != 1) { ++factors[n]; } cout << sum(factors.begin(), factors.end(), 1) << endl; return 0; }