結果

問題 No.2074 Product is Square ?
ユーザー CleyLCleyL
提出日時 2023-12-06 02:15:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,025 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 144,900 KB
実行使用メモリ 13,352 KB
最終ジャッジ日時 2023-12-06 02:15:44
合計ジャッジ時間 19,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,876 KB
testcase_01 AC 1,168 ms
6,548 KB
testcase_02 AC 1,084 ms
6,548 KB
testcase_03 AC 1,101 ms
6,548 KB
testcase_04 AC 1,075 ms
6,548 KB
testcase_05 AC 1,189 ms
6,548 KB
testcase_06 AC 1,165 ms
6,548 KB
testcase_07 AC 1,181 ms
6,548 KB
testcase_08 AC 1,104 ms
6,548 KB
testcase_09 AC 1,113 ms
6,548 KB
testcase_10 AC 1,089 ms
6,548 KB
testcase_11 AC 165 ms
6,548 KB
testcase_12 AC 1,018 ms
6,548 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/sakflat/CP/_library/cpp/template/template.cpp"

//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};




template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
 /*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/*
function corner below
*/


/*
Function corner above
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
*/
template <typename T>
T uPow(T z,T n, T mod){
  T ans = 1;
  while(n != 0){
    if(n%2){
      ans*=z;
      if(mod)ans%=mod;
    }
    n >>= 1;
    z*=z;
    if(mod)z%=mod;
  }
  return ans;
}
#line 2 "/home/sakflat/CP/_library/cpp/math/miller-rabin.cpp"
/*
 * true: 素数
 * false: 合成数
 */
template<typename T>
bool MillerRabinCheck(T n){
  if(n == 1)return false;
  if(n%2 == 0){
    return n == 2;
  }
  __int128 d = n-1;
  __int128 s = 0;
  while(d%2 == 0){
    d/=2;
    s++;
  }
  vector<__int128> base = {2,3,5,7,11,13,17,19,23,29,31,37};
  for(int i = 0; base.size() > i; i++){
    if(base[i] >= n)break;
    long long current = (long long)uPow(base[i],d,(__int128)n);
    if(current == 1 || current == n-1)continue;
    bool ok = false;
    for(int j = 0; s > j; j++){
      current = ((__int128)current * (__int128)current) % n;
      if(current == n-1){
        ok = true;
        break;
      }
    }
    if(!ok)return false;
  }
  return true;
}
#line 2 "/home/sakflat/CP/_library/cpp/math/rho.cpp"

using namespace std;
template <typename T>
struct Rho{
	mt19937 mt; //32 bit version
	T N;
  vector<T> factor;
  //std::mt19937_64 mt(rnd()); //64 bit version
  Rho(T n):N(n){
	  random_device rnd;
    mt.seed(rnd());
  }


  vector<T> run(){
    factor = factors(N);
    sort(factor.begin(), factor.end());
    return factor;
  }

private:
  __int128 c;
  T f(__int128 x, T n){
    return (x*x + c)%n;
  }

  T find_factor(T n){
    c = mt()%n;
    T base = mt()%n;
    T d = 1;
    T x = base;
    T y = base;
    while(true){
      x = f(x, n);
      y = f(f(y,n),n);
      d = __gcd(abs(x-y), n);
      if(d == n){
        return -1;
      }else if(d != 1){
        return d;
      }
    }
  }

  vector<T> factors(T n){
    if(n == 1)return {};
    if(n == 4)return {2, 2};
    if(MillerRabinCheck(n)){
      return {n};
    }

    T factor = -1;
    while(factor == -1){
      factor = find_factor(n);
    }

    vector<T> f1 = factors(factor);
    vector<T> f2 = factors(n/factor);
    f1.insert(f1.end(), f2.begin(), f2.end());

    return f1;
  }
};

void solve(){
  int n;cin>>n;
  map<int,int> Z;
  for(int i = 0; n > i; i++){
    long long x;cin>>x;
    Rho A(x); A.run();
    for(int j = 0; A.factor.size() > j; j++){
      Z[A.factor[j]]++;
    }
  }
  for(auto z: Z){
    if(z.second%2 != 0){
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  return;
}

int main(){
  int t;cin>>t;
  for(int i = 0; t > i; i++)solve();

  return 0;
}
0