結果

問題 No.3691 Calculate Mu Sum
コンテスト
ユーザー hitori6541
提出日時 2026-09-12 08:38:57
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 2,472 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 72 ms
コンパイル使用メモリ 81,408 KB
実行使用メモリ 287,744 KB
最終ジャッジ日時 2026-09-12 08:39:19
合計ジャッジ時間 19,757 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 8 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

f = Eratos(10**7)
def g(x):
    ret = 1
    if len(x) == 0:
        return 1
    for p in x:
        if x[p] > 1:
            return 0
        ret *= -1
    return ret

n = int(input())
ans = 0
for i in range(1,n+1):
    ans += g(f.factorize(i))
print(ans)
0