結果

問題 No.1653 Squarefree
ユーザー hir355hir355
提出日時 2021-08-20 23:27:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 106,160 KB
最終ジャッジ日時 2023-08-04 11:50:21
合計ジャッジ時間 11,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 295 ms
105,668 KB
testcase_01 AC 116 ms
89,332 KB
testcase_02 AC 115 ms
88,988 KB
testcase_03 AC 126 ms
89,452 KB
testcase_04 AC 116 ms
89,200 KB
testcase_05 AC 117 ms
89,324 KB
testcase_06 AC 119 ms
89,196 KB
testcase_07 AC 115 ms
88,972 KB
testcase_08 AC 115 ms
89,228 KB
testcase_09 AC 115 ms
89,324 KB
testcase_10 AC 115 ms
89,304 KB
testcase_11 AC 209 ms
105,616 KB
testcase_12 AC 209 ms
105,632 KB
testcase_13 AC 299 ms
105,628 KB
testcase_14 AC 295 ms
105,928 KB
testcase_15 AC 292 ms
106,032 KB
testcase_16 AC 294 ms
105,744 KB
testcase_17 AC 283 ms
105,324 KB
testcase_18 AC 287 ms
105,588 KB
testcase_19 AC 293 ms
105,708 KB
testcase_20 AC 293 ms
106,160 KB
testcase_21 AC 302 ms
106,028 KB
testcase_22 AC 287 ms
105,940 KB
testcase_23 AC 287 ms
105,404 KB
testcase_24 AC 291 ms
105,316 KB
testcase_25 AC 308 ms
105,936 KB
testcase_26 AC 299 ms
105,428 KB
testcase_27 AC 292 ms
105,696 KB
testcase_28 AC 292 ms
105,960 KB
testcase_29 AC 312 ms
105,868 KB
testcase_30 AC 313 ms
105,040 KB
testcase_31 AC 293 ms
105,540 KB
testcase_32 AC 301 ms
105,380 KB
testcase_33 AC 293 ms
105,600 KB
testcase_34 AC 297 ms
105,352 KB
testcase_35 AC 292 ms
105,588 KB
testcase_36 AC 126 ms
89,360 KB
testcase_37 AC 126 ms
89,540 KB
testcase_38 AC 129 ms
89,592 KB
testcase_39 AC 129 ms
89,380 KB
testcase_40 AC 127 ms
89,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

l, r = map(int, input().split())
k = list(range(l, r + 1))
d = [1] * (r - l + 1)
pr = primes(1000000)
for p in pr:
    x = 1
    while x * p <= r:
        x *= p
        for i in range(l + x - 1 - (l + x - 1) % x, r + 1, x):
            k[i - l] //= p
    t = p * p
    for i in range(l + t - 1 - (l + t - 1) % t, r + 1, t):
        d[i - l] = 0
ans = r - l + 1
for i in range(r - l + 1):
    if d[i] == 0 or (k[i] > 1 and int((k[i]+1)**.5)**2==k[i]):
        ans -= 1
print(ans)
0