結果

問題 No.854 公平なりんご分配
ユーザー snrnsidysnrnsidy
提出日時 2021-11-01 01:50:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 199,368 KB
実行使用メモリ 130,012 KB
最終ジャッジ日時 2024-04-17 19:15:03
合計ジャッジ時間 19,466 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
7,528 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 5 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 6 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 7 ms
6,944 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 5 ms
6,940 KB
testcase_29 AC 3 ms
7,772 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 6 ms
7,784 KB
testcase_32 AC 48 ms
30,292 KB
testcase_33 AC 106 ms
18,176 KB
testcase_34 AC 185 ms
39,316 KB
testcase_35 AC 112 ms
32,500 KB
testcase_36 AC 85 ms
6,944 KB
testcase_37 AC 48 ms
28,688 KB
testcase_38 AC 29 ms
26,256 KB
testcase_39 AC 358 ms
41,880 KB
testcase_40 AC 131 ms
15,964 KB
testcase_41 AC 127 ms
26,868 KB
testcase_42 AC 142 ms
39,372 KB
testcase_43 AC 251 ms
28,532 KB
testcase_44 AC 237 ms
36,652 KB
testcase_45 AC 249 ms
10,320 KB
testcase_46 AC 356 ms
35,248 KB
testcase_47 AC 90 ms
22,220 KB
testcase_48 AC 116 ms
37,556 KB
testcase_49 AC 99 ms
38,932 KB
testcase_50 AC 34 ms
28,460 KB
testcase_51 AC 344 ms
37,104 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 TLE -
testcase_83 AC 294 ms
123,600 KB
testcase_84 TLE -
testcase_85 AC 119 ms
123,560 KB
testcase_86 AC 68 ms
123,372 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 2,066 ms
123,616 KB
testcase_93 AC 2,067 ms
123,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std; 

bool isprime[2001];
vector <int> prime;
int A[100001];
int psum[100001][303];
int n,q;
int P[100000];
int L[100000];
int R[100000];
int idx[2001];

long long int mypow(long long int x,long long int n,long long int m)
{
	long long int res = 1;
	while(n > 0)
	{
		if(n%2==1)
		{
			res *= x;
			res%=m;
		}
		x *= x;
		x%=m;
		n/=2;
	}
	return res;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	memset(isprime,true,sizeof(isprime));

	for(int i=2;i<=2000;i++)
	{
		if(isprime[i])
		{
			prime.push_back(i);
			for(int j=2*i;j<=2000;j+=i)
			{
				isprime[j] = false;
			}
		}
	}

	cin >> n;

	for(int i=1;i<=n;i++)
	{
		cin >> A[i];
	}

	cin >> q;

	for(int i=0;i<q;i++)
	{
		cin >> P[i] >> L[i] >> R[i];
	}

	for(int i=0;i<prime.size();i++)
	{
		idx[prime[i]] = i;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<prime.size();j++)
		{
			psum[i][j] += psum[i-1][j];
		}
		int temp = A[i];
		for(int j=0;j<prime.size();j++)
		{
			if(temp==1 || prime[j]*prime[j] > temp) break;
			while(1)
			{
				if(temp%prime[j]!=0) break;
				temp/=prime[j];
				psum[i][j]++;
			}
		}	
		if(temp > 1)
		{
			psum[i][idx[temp]]++;
		}
	}

	for(int i=0;i<q;i++)
	{
		long long int val = 1;
		for(int j=0;j<prime.size();j++)
		{
			val*=mypow(prime[j],psum[R[i]][j] - psum[L[i]-1][j],P[i]);
			val%=P[i];
			if(val==0) break;
		}
		if(val==0)
		{
			cout << "Yes" << '\n';
		}
		else
		{
			cout << "NO" << '\n';
		}
	}


	return 0;
}
0