結果

問題 No.1665 quotient replace
ユーザー bluemegane
提出日時 2021-09-10 09:53:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 478 ms / 3,000 ms
コード長 1,586 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 109,240 KB
実行使用メモリ 100,040 KB
最終ジャッジ日時 2025-01-02 16:27:01
合計ジャッジ時間 13,355 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

class Eratosthenes
{
    public int[] Table;
    public Eratosthenes(int max)
    {
        CreateTable(max);
    }
    private void CreateTable(int n)
    {
        Table = Enumerable.Range(0, n + 1).ToArray();
        if (n <= 3) return;
        for (int i = 2; i <= n; i += 2) Table[i] = 2;
        for (int p = 3; p * p <= n; p += 2)
        {
            if (Table[p] < p) continue;
            for (int x = p; x <= n; x += p) Table[x] = p;
        }
    }
    public bool IsPrime(int n) => Table[n] == n;
    public int CountPrimes(int n)
    {
        var count = 0;
        while (Table[n] != 1)
        {
            n /= Table[n];
            count++;
        }
        return count;
    }
    public List<int> PrimeFactors(int n)
    {
        var res = new List<int>();
        while (Table[n] != 1)
        {
            res.Add(Table[n]);
            n /= Table[n];
        }
        return res;
    }
}

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        if (n == 1) { Console.WriteLine(a[0] == 1 ? "black" : "white"); return; }
        var e = new Eratosthenes(1000000);
        var x = e.CountPrimes(a[0]) ^ e.CountPrimes(a[1]);
        for (int i = 2; i < n; i++) x ^= e.CountPrimes(a[i]);
        Console.WriteLine(x == 0 ? "black" : "white");
    }
}
0