結果

問題 No.2045 Two Reflections
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 22:23:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 67,444 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-04-17 01:03:01
合計ジャッジ時間 1,692 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 6 ms
6,144 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 6 ms
5,632 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 6 ms
5,632 KB
testcase_08 AC 7 ms
5,760 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 7 ms
6,016 KB
testcase_21 AC 8 ms
6,272 KB
testcase_22 AC 7 ms
6,016 KB
testcase_23 AC 8 ms
6,144 KB
testcase_24 AC 7 ms
6,144 KB
testcase_25 AC 7 ms
6,144 KB
testcase_26 AC 7 ms
6,016 KB
testcase_27 AC 6 ms
6,144 KB
testcase_28 AC 6 ms
6,016 KB
testcase_29 AC 6 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N,P,Q;
int to[2<<17];
bool vis[2<<17];
int isp[2<<17];
int mx[2<<17];
int main()
{
	cin>>N>>P>>Q;
	if(P==1&&Q==1)
	{
		cout<<1<<endl;
		return 0;
	}
	if(P==1||Q==1)
	{
		cout<<2<<endl;
		return 0;
	}
	if(P+Q<=N)
	{
		cout<<4<<endl;
		return 0;
	}
	for(int i=0;i<N;i++)
	{
		{//P
			if(i<P)to[i]=N+(P-i-1);
			else to[i]=N+i;
		}
		{//Q
			if(N-Q<=i)to[N+i]=N-1-(i-(N-Q));
			else to[N+i]=i;
		}
	}
	for(int p=2;p<=2*N;p++)if(isp[p]==0)
	{
		mx[p]=1;
		for(int i=p;i<=2*N;i+=p)isp[i]=p;
	}
	for(int i=0;i<N;i++)if(!vis[i])
	{
		int u=i;
		int c=0;
		while(!vis[u])
		{
			c++;
			vis[u]=true;
			u=to[u];
		}
		assert(u<N);
		while(c>1)
		{
			int p=isp[c];
			int q=1;
			while(c%p==0)c/=p,q*=p;
			mx[p]=max(mx[p],q);
		}
	}
	mint ans=1;
	for(int p=2;p<=2*N;p++)if(isp[p]==p)ans*=mx[p];
	cout<<ans.val()<<endl;
}
0