結果
問題 | No.2074 Product is Square ? |
ユーザー |
|
提出日時 | 2022-09-17 18:51:55 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,704 bytes |
コンパイル時間 | 3,572 ms |
コンパイル使用メモリ | 116,124 KB |
実行使用メモリ | 27,856 KB |
最終ジャッジ日時 | 2024-12-22 00:55:35 |
合計ジャッジ時間 | 8,108 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 WA * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using static System.Console;using System.Linq;using System.Collections.Generic;class Program{static int NN => int.Parse(ReadLine());static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();static void Main(){Solve();}static void Solve(){var t = NN;var res = new bool[t];for (var u = 0; u < t; ++u){var n = NN;var a = NList;var list = new List<long>();foreach (var ai in a) if (!IsSquare(ai)) list.Add(ai);while (list.Count > 0){var flg = false;for (var i = 1; i < list.Count; ++i){var gcd = GCD(list[0], list[i]);list[0] /= gcd;list[i] /= gcd;if (IsSquare(list[i])) list.RemoveAt(i);if (IsSquare(list[0])){flg = true;list.RemoveAt(0);break;}}if (!flg){break;}}res[u] = list.Count == 0;}WriteLine(string.Join("\n", res.Select(f => f ? "Yes" : "No")));}static long GCD(long a, long b){if (a < b) return GCD(b, a);if (a % b == 0) return b;return GCD(b, a % b);}static bool IsSquare(long a){var sq = (long)Math.Sqrt(a);return sq * sq == a || (sq + 1) * (sq + 1) == a;}}