結果
| 問題 |
No.2074 Product is Square ?
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-02-17 00:07:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,823 bytes |
| コンパイル時間 | 1,595 ms |
| コンパイル使用メモリ | 141,024 KB |
| 最終ジャッジ日時 | 2025-02-19 15:11:32 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 TLE * 1 -- * 20 |
ソースコード
//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;
}
/*
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;
}
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<long long, int> Z;
for(int i = 0; n > i; i++){
long long x;cin>>x;
Rho A(x); A.run();
for(auto el: A.factor){
Z[el]++;
}
}
for(auto z: Z){
if(z.second%2){
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
return;
}
int main(){
int t;cin>>t;
for(int i = 0; t > i; i++)solve();
return 0;
}