結果

問題 No.2645 Sum of Divisors?
ユーザー ripityripity
提出日時 2024-02-21 15:23:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 203,568 KB
実行使用メモリ 81,800 KB
最終ジャッジ日時 2024-02-21 15:24:02
合計ジャッジ時間 7,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
81,544 KB
testcase_01 AC 49 ms
81,544 KB
testcase_02 AC 159 ms
81,800 KB
testcase_03 AC 39 ms
81,544 KB
testcase_04 AC 39 ms
81,544 KB
testcase_05 AC 40 ms
81,544 KB
testcase_06 AC 267 ms
81,800 KB
testcase_07 AC 255 ms
81,800 KB
testcase_08 AC 39 ms
81,544 KB
testcase_09 AC 39 ms
81,544 KB
testcase_10 AC 39 ms
81,544 KB
testcase_11 AC 39 ms
81,544 KB
testcase_12 AC 39 ms
81,544 KB
testcase_13 AC 39 ms
81,544 KB
testcase_14 AC 40 ms
81,544 KB
testcase_15 AC 40 ms
81,544 KB
testcase_16 AC 49 ms
81,544 KB
testcase_17 AC 47 ms
81,544 KB
testcase_18 AC 40 ms
81,800 KB
testcase_19 WA -
testcase_20 AC 41 ms
81,800 KB
testcase_21 WA -
testcase_22 AC 42 ms
81,800 KB
testcase_23 WA -
testcase_24 AC 60 ms
81,800 KB
testcase_25 AC 55 ms
81,800 KB
testcase_26 AC 67 ms
81,800 KB
testcase_27 AC 73 ms
81,800 KB
testcase_28 AC 116 ms
81,800 KB
testcase_29 AC 249 ms
81,800 KB
testcase_30 AC 122 ms
81,800 KB
testcase_31 AC 164 ms
81,800 KB
testcase_32 AC 208 ms
81,800 KB
testcase_33 AC 128 ms
81,800 KB
testcase_34 AC 196 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( int i = 1; i <= H_SIZE; i++ ) {
        H[i] = H[i-1]+pow(i, -1.0);
    }
    long long N;
    cin >> N;
    double ans = 0;
    long long sqrtn = floor(sqrt(N));
    if( N <= 2e6 ) {
        for( int n = 1; n <= N; n++ ) {
            ans += pow(n, -1.0)*H[N/n];
        }
    }else {
        for( int n = 1; n <= sqrtn; n++ ) {
            ans += pow(n, -1.0)*H_approximate(N/n);
        }
        for( int k = 1; k <= sqrtn-1; k++ ) {
            ans += (H_approximate(N/k)-H_approximate(N/(k+1)))*H[k];
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
}
0