結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
7,656 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 6 ms
6,944 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 8 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 7 ms
6,944 KB
testcase_27 AC 5 ms
6,944 KB
testcase_28 AC 5 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 7 ms
6,944 KB
testcase_32 AC 52 ms
30,448 KB
testcase_33 AC 112 ms
18,040 KB
testcase_34 AC 200 ms
38,836 KB
testcase_35 AC 130 ms
31,168 KB
testcase_36 AC 96 ms
6,944 KB
testcase_37 AC 54 ms
28,824 KB
testcase_38 AC 36 ms
24,244 KB
testcase_39 AC 408 ms
41,564 KB
testcase_40 AC 134 ms
16,820 KB
testcase_41 AC 132 ms
26,572 KB
testcase_42 AC 147 ms
39,168 KB
testcase_43 AC 257 ms
27,428 KB
testcase_44 AC 243 ms
36,920 KB
testcase_45 AC 250 ms
10,736 KB
testcase_46 AC 366 ms
35,004 KB
testcase_47 AC 93 ms
21,960 KB
testcase_48 AC 125 ms
38,820 KB
testcase_49 AC 107 ms
39,180 KB
testcase_50 AC 39 ms
28,232 KB
testcase_51 AC 356 ms
37,176 KB
testcase_52 TLE -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

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];

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=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) break;
			while(1)
			{
				if(temp%prime[j]!=0) break;
				temp/=prime[j];
				psum[i][j]++;
			}
		}
	}

	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