結果
問題 |
No.2645 Sum of Divisors?
|
ユーザー |
![]() |
提出日時 | 2024-02-19 22:44:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 188 ms / 2,000 ms |
コード長 | 1,700 bytes |
コンパイル時間 | 2,188 ms |
コンパイル使用メモリ | 193,588 KB |
最終ジャッジ日時 | 2025-02-19 17:24:58 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#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; } }