結果

問題 No.2645 Sum of Divisors?
ユーザー 遭難者遭難者
提出日時 2024-02-19 23:08:49
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,138 bytes
コンパイル時間 6,393 ms
コンパイル使用メモリ 344,428 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 23:09:02
合計ジャッジ時間 10,852 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 20 ms
6,676 KB
testcase_02 AC 43 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 75 ms
6,676 KB
testcase_07 AC 76 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 19 ms
6,676 KB
testcase_17 AC 15 ms
6,676 KB
testcase_18 AC 65 ms
6,676 KB
testcase_19 AC 56 ms
6,676 KB
testcase_20 AC 1,488 ms
6,676 KB
testcase_21 AC 1,140 ms
6,676 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 10 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 12 ms
6,676 KB
testcase_27 AC 15 ms
6,676 KB
testcase_28 AC 33 ms
6,676 KB
testcase_29 AC 75 ms
6,676 KB
testcase_30 AC 31 ms
6,676 KB
testcase_31 AC 45 ms
6,676 KB
testcase_32 AC 60 ms
6,676 KB
testcase_33 AC 32 ms
6,676 KB
testcase_34 AC 56 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long double ldouble;
#undef long
#define long long long
#define ll long
#define vec vector
using namespace std;
using mint = atcoder::modint;
ostream &operator<<(ostream &os, mint a)
{
	return os << a.val();
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &a)
{
	const int n = a.size();
	rep(i, n)
	{
		os << a[i];
		if (i + 1 != n)
			os << " ";
	}
	return os;
}
template <typename T, size_t n>
ostream &operator<<(ostream &os, array<T, n> &a)
{
	rep(i, n) os << a[i] << " \n"[i + 1 == n];
	return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &a)
{
	for (T &i : a)
		is >> i;
	return is;
}
template <typename T>
bool chmin(T &x, T y)
{
	if (x > y)
	{
		x = y;
		return true;
	}
	return false;
}
template <typename T>
bool chmax(T &x, T y)
{
	if (x < y)
	{
		x = y;
		return true;
	}
	return false;
}
ldouble harmonic(long n)
{
	if (n <= 1e3)
	{
		ldouble ans = 0;
		for (long i = 1; i <= n; i++)
			ans += 1.0 / i;
		return ans;
	}
	ldouble ans = log(n) + 0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495;
	ans += 1.0 / (2 * n);
	if (n <= 1e8)
		ans -= 1.0 / (12 * n * n);
	if (n <= 1e5)
		ans += 1.0 / (24 * n * n * n);
	return ans;
}
void solve()
{
	long n;
	cin >> n;
	if (n <= 1e8)
	{
		ldouble ans = 0;
		for (long i = 1; i <= n; i++)
		{
			for (long j = i; j <= n; j += i)
			{
				ans += 1.0 / j;
			}
		}
		cout << ans << endl;
		return;
	}
	const long nn = (int)sqrt(n);
	ldouble ans = 0;
	for (long i = 1; i <= nn; i++)
	{
		ans += harmonic(n / i) / i;
		ans += harmonic(i) * (harmonic(n / i) - harmonic(n / (i + 1)));
	}
	if (n <= 1e9)
		ans -= 0.01;
	cout << ans << endl;
}
int main()
{
	// srand((unsigned)time(NULL));
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(400);
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	return 0;
}
0