結果

問題 No.278 連続する整数の和(2)
ユーザー kimiyukikimiyuki
提出日時 2016-11-01 17:55:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 90,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 22:48:22
合計ジャッジ時間 1,762 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
vector<int> sieve_of_eratosthenes(int n) { // enumerate primes in [2,n] with O(n log log n)
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i*i <= n; ++i)
        if (is_prime[i])
            for (int k = i+i; k <= n; k += i)
                is_prime[k] = false;
    vector<int> primes;
    for (int i = 2; i <= n; ++i)
        if (is_prime[i])
            primes.push_back(i);
    return primes;
}
map<ll,int> factors(ll n, vector<int> const & primes) {
    map<ll,int> result;
    for (int p : primes) {
        if (n < p *(ll) p) break;
        while (n % p == 0) {
            result[p] += 1;
            n /= p;
        }
    }
    if (n != 1) result[n] += 1;
    return result;
}
ll f(ll x) {
    vector<int> primes = sieve_of_eratosthenes(sqrt(x) + 3);
    ll result = 1;
    for (auto it : factors(x, primes)) {
        ll p; int cnt; tie(p, cnt) = it;
        ll acc = 1;
        ll e = 1; repeat (i, cnt) { e *= p; acc += e; }
        result *= acc;
    }
    return result;
}
int main() {
    ll n; cin >> n;
    ll x = n % 2 == 0 ? n/2 : n;
    cout << f(x) << endl;
    return 0;
}
0