結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 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 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 6 ms
5,376 KB
testcase_32 AC 49 ms
28,800 KB
testcase_33 AC 110 ms
17,408 KB
testcase_34 AC 192 ms
38,400 KB
testcase_35 AC 115 ms
30,976 KB
testcase_36 AC 91 ms
5,376 KB
testcase_37 AC 50 ms
27,392 KB
testcase_38 AC 31 ms
22,784 KB
testcase_39 AC 368 ms
40,960 KB
testcase_40 AC 135 ms
15,232 KB
testcase_41 AC 131 ms
25,472 KB
testcase_42 AC 145 ms
37,888 KB
testcase_43 AC 259 ms
26,496 KB
testcase_44 AC 239 ms
35,456 KB
testcase_45 AC 247 ms
9,984 KB
testcase_46 AC 357 ms
34,944 KB
testcase_47 AC 92 ms
21,120 KB
testcase_48 AC 119 ms
37,120 KB
testcase_49 AC 99 ms
38,144 KB
testcase_50 AC 35 ms
27,008 KB
testcase_51 AC 337 ms
36,736 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 295 ms
123,488 KB
testcase_84 TLE -
testcase_85 AC 119 ms
123,428 KB
testcase_86 AC 93 ms
123,624 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 2,069 ms
123,516 KB
testcase_93 AC 2,080 ms
123,588 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