結果

問題 No.2829 GCD Divination
ユーザー shobonvip
提出日時 2024-08-03 13:19:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,631 bytes
コンパイル時間 3,928 ms
コンパイル使用メモリ 253,992 KB
最終ジャッジ日時 2025-02-23 20:49:12
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 MLE * 1 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	vector<vector<int>> d(n+1, vector<int>(0));
	rep(i,1,n+1){
		for(int j=i; j<=n; j+=i){
			d[j].push_back(i);
		}
	}

	vector<long double> dp(n+1);
	for (int i=2; i<=n; i++){
		int sz = d[i].size();
		vector<ll> vs(sz);
		long double tr = 0;
		for (int j=sz-1; j>=0; j--){
			vs[j] = i / d[i][j];
			for (int k=j+1; k<sz; k++){
				if(d[i][k] % d[i][j] == 0){
					vs[j] -= vs[k];
				}
			}
			tr += vs[j] * dp[d[i][j]];
		}
		tr += 1;
		tr *= (long double)i / (long double)(i-1);
		dp[i] = tr;
	}
	cout << fixed << setprecision(15);
	cout << dp[n] << '\n';

}

0