結果
| 問題 |
No.3187 Mingle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-20 21:53:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 697 ms / 2,500 ms |
| コード長 | 583 bytes |
| コンパイル時間 | 960 ms |
| コンパイル使用メモリ | 72,248 KB |
| 実行使用メモリ | 39,892 KB |
| 最終ジャッジ日時 | 2025-06-20 21:53:52 |
| 合計ジャッジ時間 | 16,228 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#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;
}