結果

問題 No.2645 Sum of Divisors?
ユーザー RubikunRubikun
提出日時 2024-02-19 22:44:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 203,052 KB
実行使用メモリ 160,244 KB
最終ジャッジ日時 2024-02-19 22:44:18
合計ジャッジ時間 5,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
159,988 KB
testcase_01 AC 71 ms
159,988 KB
testcase_02 AC 97 ms
160,244 KB
testcase_03 AC 69 ms
159,988 KB
testcase_04 AC 68 ms
159,988 KB
testcase_05 AC 68 ms
159,988 KB
testcase_06 AC 103 ms
160,244 KB
testcase_07 AC 103 ms
160,244 KB
testcase_08 AC 69 ms
159,988 KB
testcase_09 AC 71 ms
159,988 KB
testcase_10 AC 72 ms
159,988 KB
testcase_11 AC 71 ms
159,988 KB
testcase_12 AC 70 ms
159,988 KB
testcase_13 AC 68 ms
159,988 KB
testcase_14 AC 68 ms
159,988 KB
testcase_15 AC 68 ms
159,988 KB
testcase_16 AC 69 ms
159,988 KB
testcase_17 AC 70 ms
159,988 KB
testcase_18 AC 95 ms
159,988 KB
testcase_19 AC 87 ms
159,988 KB
testcase_20 AC 88 ms
160,244 KB
testcase_21 AC 89 ms
160,244 KB
testcase_22 AC 90 ms
160,244 KB
testcase_23 AC 87 ms
160,244 KB
testcase_24 AC 88 ms
160,244 KB
testcase_25 AC 88 ms
160,244 KB
testcase_26 AC 89 ms
160,244 KB
testcase_27 AC 89 ms
160,244 KB
testcase_28 AC 93 ms
160,244 KB
testcase_29 AC 103 ms
160,244 KB
testcase_30 AC 111 ms
160,244 KB
testcase_31 AC 99 ms
160,244 KB
testcase_32 AC 100 ms
160,244 KB
testcase_33 AC 94 ms
160,244 KB
testcase_34 AC 99 ms
160,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=20000005,INF=1<<30;

double rui[MAX];

const double eu=0.577215664901532860606512090082;

ll floormore(ll a,ll b){
    return a/b;
}
// max x , s.t. floor(a/x) >= b

ll floorless(ll a,ll b){
    return (a+b+1)/(b+1);
}
// min x , s.t. floor(a/x) <= b

ll ceilmore(ll a,ll b){
    if(b==1) return a+1;
    return (a-1)/(b-1);
}
// max x , s.t. ceil(a/x) >= b

ll ceilless(ll a,ll b){
    return (a+b-1)/b;
}
// min x , s.t. ceil(a/x) <= b

double f(ll x){
    if(x<MAX) return rui[x];
    else return log(x+1)+(double)(x)/2/(x+1)+eu-1.0/2;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    for(int i=1;i<MAX;i++){
        rui[i]=rui[i-1]+1.0/i;
    }
    cout<<fixed<<setprecision(25);
    
    ll N;cin>>N;
    
    if(N<=1000000){
        double ans=0;
        for(ll x=1;x<=1000000;x++){
            ans+=f(N/x)/x;
        }
        cout<<ans<<endl;
    }else{
        double ans=0;
        for(ll x=1;x<=1000000;x++){
            ans+=f(N/x)/x;
        }
        for(ll x=1;x<=1000000;x++){
            ll l=floorless(N,x),r=floormore(N,x);
            chmax(l,1000001LL);
            if(l<=r){
                ans+=(f(r)-f(l-1))*rui[x];
            }
        }
        cout<<ans<<endl;
    }
}

0