結果

問題 No.854 公平なりんご分配
ユーザー そすうぽよ
提出日時 2019-07-26 22:40:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 2,371 ms
コンパイル使用メモリ 200,580 KB
最終ジャッジ日時 2025-01-07 08:17:24
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 55 TLE * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(303, vecint(n+1, 0));
  auto pp = pl(2000);
  int np = pp.size();
  REP(i,n) {
    int b;
    cin>>b;
    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;
    REP(j,303) {
      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;
}
0