結果

問題 No.1653 Squarefree
ユーザー LyricalMaestro
提出日時 2025-05-05 21:16:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,462 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 82,552 KB
実行使用メモリ 226,940 KB
最終ジャッジ日時 2025-05-05 21:17:29
合計ジャッジ時間 40,462 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1653

import math

def main():
    L, R = map(int, input().split())

    # 10 ** 6 以下の素数をまず列挙
    target_max = 10 ** 6
    primes = []
    is_prime = [True] * (target_max + 1)
    for p in range(2, target_max + 1):
        if not is_prime[p]:
            continue

        x = 2 * p
        primes.append(p)
        while x <= target_max:
            is_prime[x] = False
            x += p
        
    target_divisors = {}
    for l in range(L, R + 1):
        target_divisors[l] = []

    for p in primes:
        q = R // p
        v = q * p
        while v >= L:
            if v in target_divisors:
                target_divisors[v].append(p)
                if v % (p ** 2) == 0:
                    del target_divisors[v]

            v -= p
    
    # 残ったtarget_divisorたちから10**6以下の数字を割っていく
    answer = 0
    for v, single_divisors in target_divisors.items():
        for d in single_divisors:
            v //= d

        if v == 1:
            answer += 1
            continue

        low = 0
        high = 10 ** 9
        while high - low > 1:
            mid = (high + low) // 2
            if mid ** 2 <= v:
                low = mid
            else:
                high = mid
        if high ** 2 <= v:
            w = high
        else:
            w = low

        if w ** 2 < v:
            answer += 1
    print(answer)





    



if __name__ == "__main__":
    main()
0