結果

問題 No.2074 Product is Square ?
ユーザー umezoumezo
提出日時 2022-09-17 14:29:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,139 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 215,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 17:45:31
合計ジャッジ時間 3,612 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 3 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

struct Eratosthenes{
  vector<bool> isprime;
  vector<int> minfactor;
  vector<int> mobius;

  Eratosthenes(int N) : isprime(N+1,true),
                        minfactor(N+1,-1),
                        mobius(N+1,1){
    isprime[1]=false;
    minfactor[1]=1;

    for(int p=2;p<=N;++p){
      if(!isprime[p]) continue;

      minfactor[p]=p;
      mobius[p]=-1;

      for(int q=p*2;q<=N;q+=p){
        isprime[q]=false;

        if(minfactor[q]==-1) minfactor[q]=p;
        if((q/p)%p==0) mobius[q]=0;
        else mobius[q]=-mobius[q];
      }
    }
  }
                                                
  vector<pair<int,int>> factorize(int n){
    vector<pair<int,int>> res;
    while(n>1){
      int p=minfactor[n];
      int exp=0;

      while(minfactor[n]==p){
        n/=p;
        ++exp;
      }
      res.emplace_back(p, exp);
    }
    return res;
  }  

  vector<int> divisors(int n){
    vector<int> res({1});

    auto pf=factorize(n);

    for(auto p:pf){
      int s=(int)res.size();
      for(int i=0;i<s;++i){
        int v=1;
        for(int j=0;j<p.second;++j){
          v*=p.first;
          res.push_back(res[i]*v);
        }
      }
    }
    return res;
  }
};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  Eratosthenes er(100);
  vector<int> B;
  for(int i=3;i<100;i++){
    if(er.isprime[i]) B.push_back(i);
  }
  int a=B.size();
  vector<set<int>> C(a);
  rep(i,a){
    int j=0;
    while(C[i].size()<(B[i]+1)/2){
      C[i].insert(j*j%B[i]);
      j++;
    }
  }

  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    vector<ll> A(n);
    ll cnt=0;
    rep(i,n){
      cin>>A[i];
      while(A[i]%2==0){
        A[i]/=2;
        cnt++;
      }
    }
    if(cnt%2==1){
      cout<<"No"<<endl;
      continue;
    }
    
    bool b=true;
    rep(i,a){
      ll tmp=1;
      rep(j,n) tmp=tmp*(A[j]%B[i])%B[i];
      if(C[i].count(tmp)==0) b=false;
    }
    if(b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  
  return 0;
}
0