結果
| 問題 |
No.1653 Squarefree
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:28:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 981 bytes |
| コンパイル時間 | 174 ms |
| コンパイル使用メモリ | 82,664 KB |
| 実行使用メモリ | 123,032 KB |
| 最終ジャッジ日時 | 2025-06-12 13:34:25 |
| 合計ジャッジ時間 | 12,800 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 WA * 3 |
ソースコード
import math
def sieve(n):
sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False
for i in range(2, int(math.sqrt(n)) + 1):
if sieve[i]:
sieve[i*i::i] = [False] * len(sieve[i*i::i])
primes = [i for i, is_p in enumerate(sieve) if is_p]
return primes
def count_square_free(L, R):
primes = sieve(10**6)
size = R - L + 1
is_square_free = [True] * size
for p in primes:
s = p * p
if s > R:
continue
start = ((L + s - 1) // s) * s
if start > R:
continue
for k in range(start, R + 1, s):
idx = k - L
is_square_free[idx] = False
for i in range(size):
if is_square_free[i]:
x = L + i
root = math.isqrt(x)
if root * root == x:
if root > 1:
is_square_free[i] = False
return sum(is_square_free)
L, R = map(int, input().split())
print(count_square_free(L, R))
gew1fw