結果

問題 No.1665 quotient replace
ユーザー satama6satama6
提出日時 2022-10-18 23:41:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,722 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 262,572 KB
最終ジャッジ日時 2024-06-29 05:35:53
合計ジャッジ時間 12,739 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 28 WA * 12 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

class FastFactorization:
    """
    1 ~ Nの整数を全て素因数分解する O(N√N) -> O(NlogN)
    
    Parameters
    -----------
    N : int
        操作対象の上限値

    Notes
    -----------
    前処理にO(NloglogN), クエリでO(logN)    
    """
    def __init__(self, N):
        self.N = N
        self.is_prime = [True] * (N+1)
        self.min_factor = [-1] * (N+1)
        self.__Eratosthenes()

    def __Eratosthenes(self):
        """
        前処理, O(NloglogN)
        """
        self.is_prime[0] = False
        self.is_prime[1] = False
        self.min_factor[1] = 1

        for p in range(2, self.N+1):
            if not self.is_prime[p]:
                continue
            self.min_factor[p] = p
            q = p + p
            while q <= N:
                self.is_prime[q] = False
                if self.min_factor[q] == -1:
                    self.min_factor[q] = p
                q += p
            
    # 高速素因数分解
    def factorize(self, n):
        """
        素因数分解を行う,O(logN)
        
        Parameters
        -----------
        n : int
            操作対象
        
        Returns
        -----------
        res : list(tuple[int, int])
            素因数及びその指数を返す。
        """
        res = 1
        while n > 1:
            p = self.min_factor[n]
            power = 0
            while n % p == 0:
                n //= p
                power += 1
            res *= power+1
        return res



N = int(input())
A = list(map(int, input().split()))
ff = FastFactorization(max(A))
grundy = 0

for a in A:
    grundy ^= ff.factorize(a)

if grundy == 0:
    print('black')
else:
    print('white')
0