結果

問題 No.1653 Squarefree
ユーザー Kiri8128Kiri8128
提出日時 2021-08-20 22:13:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 95,276 KB
最終ジャッジ日時 2024-04-22 09:05:35
合計ジャッジ時間 12,033 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 367 ms
94,592 KB
testcase_01 AC 96 ms
86,656 KB
testcase_02 AC 91 ms
87,040 KB
testcase_03 AC 98 ms
86,528 KB
testcase_04 AC 94 ms
86,784 KB
testcase_05 AC 93 ms
86,528 KB
testcase_06 AC 95 ms
86,784 KB
testcase_07 AC 91 ms
87,092 KB
testcase_08 AC 92 ms
86,912 KB
testcase_09 AC 93 ms
86,912 KB
testcase_10 AC 93 ms
86,656 KB
testcase_11 AC 237 ms
94,904 KB
testcase_12 AC 211 ms
94,912 KB
testcase_13 AC 349 ms
94,592 KB
testcase_14 AC 364 ms
94,844 KB
testcase_15 AC 344 ms
94,592 KB
testcase_16 AC 376 ms
94,968 KB
testcase_17 AC 362 ms
94,976 KB
testcase_18 AC 361 ms
94,720 KB
testcase_19 AC 360 ms
94,868 KB
testcase_20 AC 353 ms
95,104 KB
testcase_21 AC 369 ms
94,848 KB
testcase_22 AC 358 ms
94,920 KB
testcase_23 AC 369 ms
94,720 KB
testcase_24 AC 362 ms
95,104 KB
testcase_25 AC 377 ms
94,592 KB
testcase_26 AC 354 ms
94,920 KB
testcase_27 AC 340 ms
94,832 KB
testcase_28 AC 361 ms
95,276 KB
testcase_29 AC 345 ms
94,896 KB
testcase_30 AC 354 ms
94,720 KB
testcase_31 AC 341 ms
95,092 KB
testcase_32 AC 353 ms
94,592 KB
testcase_33 AC 354 ms
94,720 KB
testcase_34 AC 377 ms
94,852 KB
testcase_35 AC 358 ms
94,848 KB
testcase_36 AC 98 ms
86,828 KB
testcase_37 AC 94 ms
87,048 KB
testcase_38 AC 93 ms
87,220 KB
testcase_39 AC 93 ms
86,528 KB
testcase_40 AC 94 ms
86,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sqrt(n):
    if n == 0: return 0
    x = 1 << (n.bit_length() + 1) // 2
    y = (x + n // x) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

N = 10 ** 6
prime_list = [] # 素数リスト
lpf = [0] * (N + 1) # 最小素因数
for i in range(2, N + 1):
    if not lpf[i]:
        lpf[i] = i
        prime_list.append(i)
    a = lpf[i]
    for p in prime_list:
        if p > a or p * i > N: break
        lpf[p*i] = p
# print("lpf =", lpf)
if 0:
    print("prime_list =", prime_list[-20:])
L, R = map(int, input().split())
# L, R = 998877, 998977
n = R - L + 1
A = [i for i in range(L, R + 1)]
if 0:
    print("A =", A)
for p in prime_list:
    l = ((L - 1) // p + 1) * p - L
    for i in range(l, n, p):
        if A[i] < 0: continue
        A[i] //= p
        if A[i] % p == 0:
            A[i] = -1
if 0:
    print("A =", A)
ans = 0
for i in range(n):
    if A[i] < 0 or (A[i] > 1 and sqrt(A[i]) ** 2 == A[i]):
        pass
    else:
        ans += 1
if 0:
    print("A =", A)
print(ans)
0