結果

問題 No.1653 Squarefree
ユーザー gew1fw
提出日時 2025-06-12 16:52:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,402 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 129,284 KB
最終ジャッジ日時 2025-06-12 16:53:32
合計ジャッジ時間 6,814 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def sieve(n):
    sieve = [True] * (n + 1)
    sieve[0] = sieve[1] = False
    for i in range(2, int(math.isqrt(n)) + 1):
        if sieve[i]:
            sieve[i*i : n+1 : i] = [False] * len(sieve[i*i : n+1 : i])
    primes = [i for i, is_p in enumerate(sieve) if is_p]
    return primes

def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True

def count_squarefree(L, R):
    primes = sieve(10**6)
    count = 0
    for x in range(L, R + 1):
        if x == 0:
            continue
        if x == 1:
            count += 1
            continue
        square_free = True
        for p in primes:
            p_sq = p * p
            if p_sq > x:
                break
            if x % p_sq == 0:
                square_free = False
                break
        if not square_free:
            continue
        s = math.isqrt(x)
        if s * s != x:
            count += 1
        else:
            if s == 1:
                count += 1
            else:
                if not is_prime(s):
                    pass
                else:
                    pass
    return count

# Read input
L, R = map(int, input().split())
print(count_squarefree(L, R))
0