結果
| 問題 | No.3692 Calculate Mu |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-12 08:29:28 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 63 ms / 2,000 ms |
| + 942µs | |
| コード長 | 2,390 bytes |
| 記録 | |
| コンパイル時間 | 621 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 86,144 KB |
| 最終ジャッジ日時 | 2026-09-12 08:30:04 |
| 合計ジャッジ時間 | 2,451 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
from collections import Counter
class Eratos:
__slots__ = ("lim", "spf", "isprime", "primes")
def __init__(self, lim: int):
assert lim > 0
# O(lim * log(log(lim)))
self.lim = lim
spf = list(range(lim + 1))
if lim >= 1:
spf[0] = 0
spf[1] = 1
r = int(lim ** 0.5)
for p in range(2, r + 1):
if spf[p] == p:
start = p * p
step = p
for j in range(start, lim + 1, step):
if spf[j] == j:
spf[j] = p
self.spf = spf
isprime = [False]*(lim+1)
primes = []
for i in range(2,lim+1):
if spf[i] == i:
isprime[i] = True
primes.append(i)
self.isprime = isprime
self.primes = primes
def factorize_small(self, x: int):
assert 1 <= x <= self.lim
ret = Counter()
while x > 1:
p = self.spf[x]
while x % p == 0:
x //= p
ret[p] += 1
return ret
def factorize_large(self, x: int):
assert 1 <= x <= self.lim**2
ret = Counter()
for p in self.primes:
if p*p > x:
break
while x%p == 0:
x //= p
ret[p] += 1
if x > 1:
ret[x] += 1
return ret
def factorize(self, x: int) -> Counter:
assert 1 <= x <= self.lim**2
if x <= self.lim:
return self.factorize_small(x)
else:
return self.factorize_large(x)
def divisors(self, x: int, *, sort: bool = True):
"""Return list of all positive divisors of x."""
assert 1 <= x <= self.lim**2
fs = self.factorize(x) # Counter {p: e}
divs = [1]
for p, e in fs.items():
base = 1
add = []
for _ in range(e):
base *= p
# 既存のdivsそれぞれに p^k を掛ける
for d in divs:
add.append(d * base)
divs += add
if sort:
divs.sort()
return divs
n = int(input())
f = Eratos(10**6).factorize(n)
if n == 1:
print(1)
else:
if all(e==1 for _,e in f.items()):
print(pow(-1,len(f)))
else:
print(0)