結果
| 問題 |
No.854 公平なりんご分配
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-26 22:51:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,827 ms / 3,153 ms |
| コード長 | 1,381 bytes |
| コンパイル時間 | 2,366 ms |
| コンパイル使用メモリ | 200,372 KB |
| 最終ジャッジ日時 | 2025-01-07 08:28:02 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 92 |
ソースコード
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i = (k);i < (n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
using namespace std;
using vecint = vector<int>;
using ll = int64_t;
vecint pl(int n) {
vector<bool> b(n+1, true);
b[0] = b[1] = false;
for (int i = 2; i*i <= n; ++i)
if (b[i])
for (int j = i*i; j <= n; j += i)
b[j] = false;
vecint res;
REP(i,n+1)
if (b[i])
res.push_back(i);
return res;
}
int main()
{
int n;
cin>>n;
vector<vecint> v(304, vecint(n+1, 0));
auto pp = pl(2000);
int np = pp.size();
REP(i,n) {
int b;
cin>>b;
if (b == 0) {
v[303][i+1] = v[303][i] + 1;
REP(j,np) {
v[j][i+1] = v[j][i];
}
} else {
v[303][i+1] = v[303][i];
REP(j,np) {
v[j][i+1] = v[j][i];
while ((b % pp[j]) == 0) {
b /= pp[j];
++v[j][i+1];
}
}
}
}
int q;
cin>>q;
REP(i,q) {
int p,l,r;
cin>>p>>l>>r;
if (v[303][r] - v[303][l-1] > 0) {
cout << "Yes" << endl;
continue;
}
REP(j,np) {
int d = v[j][r] - v[j][l-1];
REP(k,d) {
if ((p % pp[j]) == 0) {
p /= pp[j];
} else {
break;
}
}
}
if (p == 1) {
cout << "Yes" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}