結果
問題 | No.2074 Product is Square ? |
ユーザー |
![]() |
提出日時 | 2022-09-19 14:48:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 515 ms / 2,000 ms |
コード長 | 857 bytes |
コンパイル時間 | 1,722 ms |
コンパイル使用メモリ | 168,712 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-22 02:28:26 |
合計ジャッジ時間 | 7,256 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#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; }