結果

問題 No.2074 Product is Square ?
コンテスト
ユーザー C
提出日時 2026-10-14 23:04:32
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 149 ms / 2,000 ms
+ 899µs
コード長 1,339 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,930 ms
コンパイル使用メモリ 389,596 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-21 16:26:14
合計ジャッジ時間 8,850 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
#include <boost/polygon/point_data.hpp>
#include <boost/polygon/voronoi.hpp>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pll=pair<ll,ll>;
using pi=pair<int,int>;

// using mint=modint998244353;

// using BoostPoint=boost::polygon::point_data<int>;
// using Voronoi=boost::polygon::voronoi_diagram<double>;

#line 2 "math/isqrt.hpp"

#include <cmath>
using namespace std;

// floor(sqrt(n)) を返す (ただし n が負の場合は 0 を返す)
long long isqrt(long long n) {
  if (n <= 0) return 0;
  long long x = sqrt(n);
  while ((x + 1) * (x + 1) <= n) x++;
  while (x * x > n) x--;
  return x;
}

int main()
{
  	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	cin>>T;
	while(T--){
		int N;
		cin>>N;
		vll A(N);
		rep(i,0,N)cin>>A[i];
		rep(i,0,N){
			rep(j,i+1,N){
				ll g=gcd(A[i],A[j]);
				A[i]/=g;
				A[j]/=g;
			}
		}
		bool ok=true;
		rep(i,0,N){
			ll sq=isqrt(A[i]);
			if(A[i]!=sq*sq){
				ok=false;
				break;
			}
		}
		if(ok)cout<<"Yes\n";
		else cout<<"No\n";
	}

}
0