結果

問題 No.2724 Coprime Game 1
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-23 22:57:58
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 8,227 ms
コンパイル使用メモリ 168,788 KB
実行使用メモリ 207,564 KB
最終ジャッジ日時 2024-04-23 22:58:13
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
45,952 KB
testcase_01 AC 87 ms
45,824 KB
testcase_02 AC 106 ms
45,780 KB
testcase_03 AC 103 ms
51,580 KB
testcase_04 AC 115 ms
51,412 KB
testcase_05 AC 110 ms
51,412 KB
testcase_06 AC 103 ms
48,384 KB
testcase_07 AC 111 ms
207,564 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 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[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var isPrime = Enumerable.Repeat(true, 3_000_001).ToArray();
        isPrime[0] = false;
        isPrime[1] = false;
        for (var i = 2; i < isPrime.Length; ++i)
        {
            if (!isPrime[i]) continue;
            for (var j = i * 2; j < isPrime.Length; j += i) isPrime[j] = false;
        }
        var counts = new int[isPrime.Length];
        for (var i = 1; i < counts.Length; ++i) counts[i] = counts[i - 1] + (isPrime[i] ? 1 : 0);
        var t = NN;
        var ans = new bool[t];
        for (var u = 0; u < t; ++u)
        {
            var n = NN;
            if (!isPrime[n])
            {
                var all = n - 2 - counts[n] + counts[n / 2];
                ans[u] = all % 2 == 1;
            }
        }
        WriteLine(string.Join("\n", ans.Select(f => f ? "K" : "P")));
    }
}
0