結果
問題 | No.2074 Product is Square ? |
ユーザー |
👑 |
提出日時 | 2023-12-06 02:26:57 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,071 bytes |
コンパイル時間 | 1,515 ms |
コンパイル使用メモリ | 144,740 KB |
実行使用メモリ | 10,140 KB |
最終ジャッジ日時 | 2024-09-27 00:58:49 |
合計ジャッジ時間 | 16,340 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 TLE * 1 -- * 20 |
ソースコード
#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; set<T> factor; //std::mt19937_64 mt(rnd()); //64 bit version Rho(T n):N(n){ random_device rnd; mt.seed(rnd()); } void run(){ factor = factors(N); } 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; } } } set<T> factors(T n){ if(n == 1)return {}; if(n == 4)return {}; if(MillerRabinCheck(n)){ return {n}; } T factor = -1; while(factor == -1){ factor = find_factor(n); } set<T> f1 = factors(factor); set<T> f2 = factors(n/factor); set<T> ret; for(auto el: f1){ if(!f2.count(el)){ ret.insert(el); } } for(auto el: f2){ if(!f1.count(el)){ ret.insert(el); } } return ret; } }; void solve(){ int n;cin>>n; set<int> Z; for(int i = 0; n > i; i++){ long long x;cin>>x; Rho A(x); A.run(); for(auto el: A.factor){ if(Z.count(el)){ Z.erase(el); }else{ Z.insert(el); } } } if(Z.size())cout << "No" << endl; else cout << "Yes" << endl; return; } int main(){ int t;cin>>t; for(int i = 0; t > i; i++)solve(); return 0; }