結果

問題 No.2645 Sum of Divisors?
ユーザー 👑 hitonanodehitonanode
提出日時 2024-03-02 22:54:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 109,268 KB
実行使用メモリ 11,568 KB
最終ジャッジ日時 2024-03-02 22:54:03
合計ジャッジ時間 3,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,312 KB
testcase_01 AC 6 ms
11,312 KB
testcase_02 AC 48 ms
11,568 KB
testcase_03 AC 7 ms
11,312 KB
testcase_04 AC 6 ms
11,312 KB
testcase_05 AC 6 ms
11,312 KB
testcase_06 AC 85 ms
11,568 KB
testcase_07 AC 85 ms
11,568 KB
testcase_08 AC 6 ms
11,312 KB
testcase_09 AC 6 ms
11,312 KB
testcase_10 AC 6 ms
11,312 KB
testcase_11 AC 5 ms
11,312 KB
testcase_12 AC 6 ms
11,312 KB
testcase_13 AC 5 ms
11,312 KB
testcase_14 AC 7 ms
11,312 KB
testcase_15 AC 7 ms
11,312 KB
testcase_16 AC 7 ms
11,312 KB
testcase_17 AC 7 ms
11,312 KB
testcase_18 AC 7 ms
11,568 KB
testcase_19 AC 6 ms
11,568 KB
testcase_20 AC 7 ms
11,568 KB
testcase_21 AC 7 ms
11,568 KB
testcase_22 AC 8 ms
11,568 KB
testcase_23 AC 8 ms
11,568 KB
testcase_24 AC 13 ms
11,568 KB
testcase_25 AC 11 ms
11,568 KB
testcase_26 AC 15 ms
11,568 KB
testcase_27 AC 17 ms
11,568 KB
testcase_28 AC 31 ms
11,568 KB
testcase_29 AC 82 ms
11,568 KB
testcase_30 AC 35 ms
11,568 KB
testcase_31 AC 50 ms
11,568 KB
testcase_32 AC 66 ms
11,568 KB
testcase_33 AC 36 ms
11,568 KB
testcase_34 AC 61 ms
11,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

#include <numbers>

int main() {
    long long N;
    cin >> N;

    constexpr int L = 1010101;
    vector<double> invsum(L + 1);
    for (int i = 0; i < L; ++i) invsum.at(i + 1) = invsum.at(i) + 1.0 / (i + 1);

    auto get_invsum = [&](long long n) -> double {
        if (n <= L) return invsum.at(n);
        return log(n) + std::numbers::egamma;
    };

    double ret = get_invsum(N) * 2 - 1;

    long long d = 2;

    while (d <= N) {
        long long k = N / d;
        if (k <= 0) break;
        long long r = N / k;

        ret += (get_invsum(k) - 1) * (get_invsum(r) - get_invsum(d - 1));

        d = r + 1;
    }

    cout << fixed << setprecision(13) << ret << '\n';
}
0