結果

問題 No.2645 Sum of Divisors?
ユーザー ripityripity
提出日時 2024-02-21 15:38:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 2,885 ms
コンパイル使用メモリ 203,448 KB
実行使用メモリ 81,800 KB
最終ジャッジ日時 2024-02-21 15:38:19
合計ジャッジ時間 5,789 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
81,672 KB
testcase_01 AC 39 ms
81,672 KB
testcase_02 AC 74 ms
81,800 KB
testcase_03 AC 39 ms
81,672 KB
testcase_04 AC 40 ms
81,672 KB
testcase_05 AC 39 ms
81,672 KB
testcase_06 AC 100 ms
81,800 KB
testcase_07 AC 100 ms
81,800 KB
testcase_08 AC 40 ms
81,672 KB
testcase_09 AC 39 ms
81,672 KB
testcase_10 AC 40 ms
81,672 KB
testcase_11 AC 39 ms
81,672 KB
testcase_12 AC 39 ms
81,672 KB
testcase_13 AC 40 ms
81,672 KB
testcase_14 AC 39 ms
81,672 KB
testcase_15 AC 41 ms
81,672 KB
testcase_16 AC 41 ms
81,672 KB
testcase_17 AC 39 ms
81,672 KB
testcase_18 AC 39 ms
81,672 KB
testcase_19 AC 39 ms
81,672 KB
testcase_20 AC 41 ms
81,800 KB
testcase_21 AC 40 ms
81,800 KB
testcase_22 AC 40 ms
81,800 KB
testcase_23 AC 40 ms
81,800 KB
testcase_24 AC 46 ms
81,800 KB
testcase_25 AC 43 ms
81,800 KB
testcase_26 AC 47 ms
81,800 KB
testcase_27 AC 49 ms
81,800 KB
testcase_28 AC 60 ms
81,800 KB
testcase_29 AC 101 ms
81,800 KB
testcase_30 AC 62 ms
81,800 KB
testcase_31 AC 73 ms
81,800 KB
testcase_32 AC 87 ms
81,800 KB
testcase_33 AC 63 ms
81,800 KB
testcase_34 AC 82 ms
81,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

double H_approximate(long long n) {
    const double euler_constant = 0.5772156649015328606065121;
    return log(n)+euler_constant+(1.0/2.0)*pow(n, -1.0)-(1.0/12.0)*pow(n, -2.0)+(1.0/120.0)*pow(n, -4.0);
}

int main() {
    constexpr int H_SIZE = 1e7;
    vector<double> H(H_SIZE+1);
    for( long long n = 1; n <= H_SIZE; n++ ) {
        H[n] = H[n-1]+pow(n, -1.0);
    }
    auto h = [&](long long n) -> double {
        return n <= H_SIZE ? H[n] : H_approximate(n);
    };
    long long N;
    cin >> N;
    double ans = 0;
    long long sqrtn = floor(sqrt(N));
    for( long long n = 1; n <= sqrtn; n++ ) {
        ans += pow(n, -1.0)*h(N/n);
    }
    for( long long k = 1; k <= N/(sqrtn+1); k++ ) {
        ans += (h(N/k)-h(N/(k+1)))*h(k);
    }
    cout << fixed << setprecision(10) << ans << endl;
}
0