結果

問題 No.2074 Product is Square ?
ユーザー mmn15277198mmn15277198
提出日時 2022-09-19 14:48:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 167,072 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 18:53:57
合計ジャッジ時間 7,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool is_square(long long x) {
  if (x == 1) return true;
  long long ok = 5e9;
  long long ng = 0;
  while (abs(ok - ng) > 1) {
    long long m = (ok + ng) / 2;
    if (m * m == x) return true;
    else if (m * m > x) ok = m;
    else ng = m;
  }
  if (ok * ok == x) return true;
  else return false;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    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 - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        long long g = __gcd(a[i], a[j]);
        a[i] /= g;
        a[j] /= g;
      }
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (is_square(a[i])) continue;
      ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
  }
  return 0;
}
0