結果

問題 No.2074 Product is Square ?
ユーザー tnakao0123tnakao0123
提出日時 2022-09-18 02:20:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 47,640 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 17:58:53
合計ジャッジ時間 5,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 43 ms
4,376 KB
testcase_12 AC 142 ms
4,376 KB
testcase_13 AC 499 ms
4,380 KB
testcase_14 AC 139 ms
4,380 KB
testcase_15 AC 42 ms
4,376 KB
testcase_16 AC 146 ms
4,380 KB
testcase_17 AC 499 ms
4,380 KB
testcase_18 AC 134 ms
4,376 KB
testcase_19 AC 42 ms
4,376 KB
testcase_20 AC 147 ms
4,376 KB
testcase_21 AC 498 ms
4,380 KB
testcase_22 AC 135 ms
4,376 KB
testcase_23 AC 42 ms
4,380 KB
testcase_24 AC 146 ms
4,376 KB
testcase_25 AC 498 ms
4,376 KB
testcase_26 AC 134 ms
4,380 KB
testcase_27 AC 42 ms
4,376 KB
testcase_28 AC 145 ms
4,380 KB
testcase_29 AC 498 ms
4,380 KB
testcase_30 AC 136 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- 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;
}
0