結果

問題 No.2074 Product is Square ?
ユーザー ゆにぽけゆにぽけ
提出日時 2024-03-10 09:58:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 1,463 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 132,408 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-10 09:58:24
合計ジャッジ時間 8,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 5 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 9 ms
6,676 KB
testcase_07 AC 5 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 75 ms
6,676 KB
testcase_12 AC 160 ms
6,676 KB
testcase_13 AC 508 ms
6,676 KB
testcase_14 AC 167 ms
6,676 KB
testcase_15 AC 75 ms
6,676 KB
testcase_16 AC 165 ms
6,676 KB
testcase_17 AC 510 ms
6,676 KB
testcase_18 AC 162 ms
6,676 KB
testcase_19 AC 74 ms
6,676 KB
testcase_20 AC 167 ms
6,676 KB
testcase_21 AC 512 ms
6,676 KB
testcase_22 AC 163 ms
6,676 KB
testcase_23 AC 75 ms
6,676 KB
testcase_24 AC 165 ms
6,676 KB
testcase_25 AC 533 ms
6,676 KB
testcase_26 AC 161 ms
6,676 KB
testcase_27 AC 75 ms
6,676 KB
testcase_28 AC 164 ms
6,676 KB
testcase_29 AC 508 ms
6,676 KB
testcase_30 AC 165 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
template<class T = long long>
T gcd(T a,T b)
{
	while(b)
	{
		a %= b;
		swap(a,b);
	}
	return a;
}

template<class T = long long>
T lcm(T a,T b)
{
	return a / gcd<T>(a,b) * b;
}

void Main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for(int i = 0;i < N;i++)
	{
		cin >> A[i];
	}
	for(int i = 0;i < N;i++)
	{
		for(int j = i + 1;j < N;j++)
		{
			long long g = gcd(A[i],A[j]);
			A[i] /= g;
			A[j] /= g;
		}
	}
	sort(A.begin(),A.end());
	auto sq = [](long long x) -> bool
	{
		long long ok = 0,ng = (long long)1e9 + 1;
		while(ng - ok > 1)
		{
			long long mid = (ok + ng) / 2;
			if(mid * mid <= x)
			{
				ok = mid;
			}
			else
			{
				ng = mid;
			}
		}
		return ok * ok == x;
	};
	for(int i = 0;i < N;)
	{
		int j = i;
		while(j < N && A[j] == A[i])
		{
			j++;
		}
		if(!sq(A[i]) && (j - i) & 1)
		{
			cout << "No\n";
			return;
		}
		i = j;
	}
	cout << "Yes\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	while(tt--) Main();
}

0