結果

問題 No.3187 Mingle
コンテスト
ユーザー kotatsugame
提出日時 2025-06-20 21:53:35
言語 C++14
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 204 ms / 2,500 ms
+ 296µs
コード長 583 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 410 ms
コンパイル使用メモリ 83,268 KB
実行使用メモリ 39,936 KB
最終ジャッジ日時 2026-07-12 15:13:24
合計ジャッジ時間 6,502 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint;
int N,P;
mint dp[3<<17];
vector<int>yaku[3<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>P;
	mint::set_mod(P);
	mint sum=0;
	for(int b=1;b<=N;b++)for(int a=b;a<=N;a+=b)yaku[a].push_back(b);
	for(int a=3;a<=N;a++)
	{
		mint c=0;
		for(int b:yaku[a])
		//for(int b=1;b<=a;b++)if(a%b==0)
		{
			sum-=dp[a-b];
			c++;
		}
		//dp[a] = 1 + (sum + c * dp[a])/a
		dp[a]=(a+sum)/(a-c);
		sum+=c*dp[a];
	}
	cout<<dp[N].val()<<endl;
}
0