結果

問題 No.2074 Product is Square ?
ユーザー 👑 kakel-sankakel-san
提出日時 2022-09-17 18:57:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 749 ms / 2,000 ms
コード長 1,339 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 112,348 KB
実行使用メモリ 27,912 KB
最終ジャッジ日時 2024-06-01 15:17:42
合計ジャッジ時間 9,207 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,392 KB
testcase_01 AC 34 ms
25,120 KB
testcase_02 AC 35 ms
25,248 KB
testcase_03 AC 34 ms
27,312 KB
testcase_04 AC 35 ms
27,192 KB
testcase_05 AC 33 ms
23,092 KB
testcase_06 AC 34 ms
25,536 KB
testcase_07 AC 36 ms
25,120 KB
testcase_08 AC 35 ms
27,288 KB
testcase_09 AC 35 ms
27,196 KB
testcase_10 AC 34 ms
25,392 KB
testcase_11 AC 107 ms
25,604 KB
testcase_12 AC 237 ms
27,784 KB
testcase_13 AC 738 ms
27,660 KB
testcase_14 AC 241 ms
27,792 KB
testcase_15 AC 107 ms
23,480 KB
testcase_16 AC 241 ms
25,736 KB
testcase_17 AC 749 ms
27,520 KB
testcase_18 AC 231 ms
25,616 KB
testcase_19 AC 105 ms
27,912 KB
testcase_20 AC 243 ms
25,608 KB
testcase_21 AC 742 ms
25,628 KB
testcase_22 AC 235 ms
25,740 KB
testcase_23 AC 107 ms
23,732 KB
testcase_24 AC 242 ms
25,644 KB
testcase_25 AC 745 ms
25,860 KB
testcase_26 AC 233 ms
27,536 KB
testcase_27 AC 106 ms
25,484 KB
testcase_28 AC 242 ms
25,608 KB
testcase_29 AC 741 ms
25,732 KB
testcase_30 AC 235 ms
25,732 KB
testcase_31 AC 31 ms
27,200 KB
testcase_32 AC 30 ms
24,988 KB
testcase_33 AC 31 ms
25,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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;
            for (var i = 0; i < n; ++i) for (var j = i + 1; j < n; ++j)
            {
                var gcd = GCD(a[i], a[j]);
                if (gcd > 1)
                {
                    a[i] /= gcd;
                    a[j] /= gcd;
                }
            }
            var flg = true;
            for (var i = 0; i < n; ++i)
            {
                if (!IsSquare(a[i])) flg = false;
            }
            res[u] = flg;
        }
        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