結果

問題 No.1653 Squarefree
ユーザー rlangevin
提出日時 2023-10-25 08:56:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 84,264 KB
最終ジャッジ日時 2024-09-25 04:04:27
合計ジャッジ時間 27,318 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

def isqrt(n):
    yes = 1
    no = 10 ** 9 + 5
    while no - yes != 1:
        mid = (yes + no)//2
        if mid * mid <= n:
            yes = mid
        else:
            no = mid
    return yes * yes == n

L, R = map(int, input().split())
D = list(range(L, R + 1))
M = 10 ** 6 + 5
for i in range(2, M):
    start = (L + i - 1)//i * i
    for j in range(start - L, R - L + 1, i):
        if D[j] % (i * i) == 0:
            D[j] = 0
        elif D[j] % i == 0:
            D[j] //= i

ans = 0
for i in range(R - L + 1):
    if D[i] == 1:
        ans += 1
    elif D[i] == 0:
        continue    
    elif not isqrt(D[i]):
        ans += 1

print(ans)
0