結果

問題 No.2074 Product is Square ?
ユーザー 👑 kakel-sankakel-san
提出日時 2022-09-17 18:51:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,704 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 67,960 KB
実行使用メモリ 25,948 KB
最終ジャッジ日時 2023-08-23 17:52:19
合計ジャッジ時間 7,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,836 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 131 ms
22,072 KB
testcase_12 AC 273 ms
22,096 KB
testcase_13 AC 76 ms
21,972 KB
testcase_14 AC 208 ms
21,968 KB
testcase_15 WA -
testcase_16 AC 281 ms
22,216 KB
testcase_17 AC 73 ms
22,096 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 74 ms
22,036 KB
testcase_22 AC 240 ms
22,128 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 74 ms
22,092 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 73 ms
22,040 KB
testcase_30 WA -
testcase_31 AC 65 ms
21,796 KB
testcase_32 AC 66 ms
21,736 KB
testcase_33 AC 69 ms
21,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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