結果
問題 |
No.1665 quotient replace
|
ユーザー |
![]() |
提出日時 | 2022-10-18 23:33:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,431 bytes |
コンパイル時間 | 126 ms |
コンパイル使用メモリ | 82,412 KB |
実行使用メモリ | 261,404 KB |
最終ジャッジ日時 | 2024-06-29 05:30:38 |
合計ジャッジ時間 | 12,353 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 16 WA * 24 RE * 1 |
ソースコード
# 1 ~ Nの整数を全て素因数分解する O(N√N) -> O(NlogN) class FastFactorization: def __init__(self, N): self.N = N self.is_prime = [True] * (N+1) self.min_factor = [-1] * (N+1) # min_factor[i]:整数iを割り切る最小の素数 self.Eratosthenes() # 前処理 O(N loglogN) def Eratosthenes(self): 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): res = [] while n > 1: p = self.min_factor[n] power = 0 while n % p == 0: n //= p power += 1 res.append((p, power)) return len(res) - 1 def main(self): self.Eratosthenes() for i in range(2, self.N+1): print(len(self.factorize(i))) N = int(input()) A = list(map(int, input().split())) ff = FastFactorization(max(A) + 1) grundy = 0 for a in A: grundy ^= ff.factorize(a) if grundy == 0: print('black') else: print('white')