結果

問題 No.2829 GCD Divination
ユーザー kotatsugamekotatsugame
提出日時 2024-08-02 21:39:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,811 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 88,800 KB
実行使用メモリ 81,476 KB
最終ジャッジ日時 2024-08-02 21:40:09
合計ジャッジ時間 13,984 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 276 ms
81,404 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 778 ms
81,476 KB
testcase_05 AC 1,811 ms
71,744 KB
testcase_06 AC 1,512 ms
60,000 KB
testcase_07 AC 1,316 ms
55,100 KB
testcase_08 AC 835 ms
38,492 KB
testcase_09 AC 715 ms
31,592 KB
testcase_10 AC 217 ms
47,600 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 89 ms
20,444 KB
testcase_13 AC 269 ms
74,852 KB
testcase_14 AC 219 ms
51,312 KB
testcase_15 AC 294 ms
38,408 KB
testcase_16 AC 78 ms
21,228 KB
testcase_17 AC 59 ms
13,552 KB
testcase_18 AC 50 ms
12,416 KB
testcase_19 AC 61 ms
14,976 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 305 ms
33,772 KB
testcase_22 AC 113 ms
38,616 KB
testcase_23 AC 424 ms
45,928 KB
testcase_24 AC 268 ms
66,644 KB
testcase_25 AC 297 ms
80,296 KB
testcase_26 AC 140 ms
37,400 KB
testcase_27 AC 448 ms
59,992 KB
testcase_28 AC 54 ms
15,168 KB
testcase_29 AC 232 ms
38,812 KB
testcase_30 AC 428 ms
76,352 KB
testcase_31 AC 35 ms
13,644 KB
testcase_32 AC 164 ms
46,888 KB
testcase_33 AC 163 ms
36,856 KB
testcase_34 AC 394 ms
59,656 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'long double solve(int)':
main.cpp:35:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   35 |         for(auto[v,c]:nxt)ans+=solve(gcd(v,N))*c;
      |                 ^

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
#include<iomanip>
using namespace std;
int gcd(int a,int b)
{
	while(b)
	{
		int t=a%b;
		a=b;
		b=t;
	}
	return a;
}
int to[10000001];
long double memo[10000001];
long double solve(int N)
{
	if(N==1)return 0;
	if(memo[N])return memo[N];
	vector<pair<int,int> >nxt;
	{
		vector<int>tov(to+1,to+N);
		sort(tov.begin(),tov.end());
		for(int v:tov)
		{
			if(!nxt.empty()&&nxt.back().first==v)nxt.back().second++;
			else nxt.push_back(make_pair(v,1));
		}
	}
	long double ans=0;
	for(auto[v,c]:nxt)ans+=solve(gcd(v,N))*c;
	ans+=N;
	ans/=N-1;
	return memo[N]=ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;cin>>N;
	for(int g=1;g<N;g++)if(N%g==0)for(int i=g;i<N;i+=g)to[i]=g;
	cout<<fixed<<setprecision(16)<<solve(N)<<endl;
}
0