結果
| 問題 |
No.1653 Squarefree
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:21:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,175 bytes |
| コンパイル時間 | 536 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 122,940 KB |
| 最終ジャッジ日時 | 2025-06-12 13:23:14 |
| 合計ジャッジ時間 | 12,706 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 WA * 3 |
ソースコード
import math
def is_square(n):
s = int(math.isqrt(n))
return s * s == n
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])
return [i for i, is_p in enumerate(sieve) if is_p]
def count_square_free(L, R):
primes = sieve(10**6)
is_square_free = [True] * (R - L + 1)
# Mark multiples of squares of small primes
for p in primes:
s = p * p
if s > R:
continue
first = (L + s - 1) // s
start = first * s
if start > R:
continue
for x in range(start, R + 1, s):
idx = x - L
is_square_free[idx] = False
# Check for perfect squares and handle x=1
for i in range(len(is_square_free)):
x = L + i
if x == 1:
is_square_free[i] = True
continue
if is_square_free[i]:
if is_square(x):
is_square_free[i] = False
return sum(is_square_free)
L, R = map(int, input().split())
print(count_square_free(L, R))
gew1fw