結果
| 問題 | No.2074 Product is Square ? |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-09-18 02:20:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 504 ms / 2,000 ms |
| コード長 | 1,267 bytes |
| 記録 | |
| コンパイル時間 | 346 ms |
| コンパイル使用メモリ | 49,212 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-22 01:05:24 |
| 合計ジャッジ時間 | 5,526 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2074.cc: No.2074 Product is Square ? - yukicoder
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 1000;
/* typedef */
typedef long long ll;
/* global variables */
ll as[MAX_N];
/* subroutines */
template <typename T>
T gcd(T m, T n) { // m >= 0, n >= 0
if (m < n) swap(m, n);
while (n > 0) {
T r = m % n;
m = n;
n = r;
}
return m;
}
bool is_square(ll a) {
long double x = floorl(sqrtl((long double)a + 0.5));
return a == x * x;
}
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lld", as + i);
int m = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m && as[i] > 1; j++) {
ll g = gcd(as[j], as[i]);
as[j] /= g, as[i] /= g;
}
int k = 0;
for (int j = 0; j < m; j++)
if (as[j] > 1) as[k++] = as[j];
if (as[i] > 1) as[k++] = as[i];
m = k;
}
bool ok = true;
for (int i = 0; ok && i < m; i++) ok = is_square(as[i]);
if (ok) puts("Yes");
else puts("No");
//printf("%d:", m);
//for (int i = 0; i < m; i++) printf(" %lld", as[i]); putchar('\n');
}
return 0;
}
tnakao0123