結果

問題 No.2751 429-like Number
ユーザー kakel-san
提出日時 2024-05-22 23:29:31
言語 C#
(.NET 8.0.404)
結果
TLE  
実行時間 -
コード長 1,699 bytes
コンパイル時間 9,086 ms
コンパイル使用メモリ 170,496 KB
実行使用メモリ 63,232 KB
最終ジャッジ日時 2024-12-20 18:37:19
合計ジャッジ時間 78,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 10 TLE * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (112 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var p = new List<int>();
        for (var i = 2; i < 100000; ++i)
        {
            if (IsPrime(i)) p.Add(i);
        }
        var q = NN;
        var ans = new bool[q];
        for (var i = 0; i < q; ++i)
        {
            var a = long.Parse(ReadLine());
            var x = 0;
            while (x < p.Count)
            {
                if (a % p[x] == 0) break;
                ++x;
            }
            if (x == p.Count) continue;
            var y = x;
            while (y < p.Count)
            {
                if (a / p[x] % p[y] == 0) break;
                ++y;
            }
            if (y == p.Count) continue;
            var z = a / p[x] / p[y];
            if (IsPrime(z)) ans[i] = true;
        }
        WriteLine(string.Join("\n", ans.Select(f => f ? "Yes" : "No")));
    }
    static bool IsPrime(long n)
    {
        if (n == 1) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;
        int i = 3;
        while (i * i <= n)
        {
            if (n % i == 0) return false;
            i = i + 2;
        }
        return true;
    }
}
0