結果
問題 |
No.1653 Squarefree
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:37:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,402 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,076 KB |
実行使用メモリ | 127,564 KB |
最終ジャッジ日時 | 2025-06-12 21:40:09 |
合計ジャッジ時間 | 6,781 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 37 |
ソースコード
import math 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]) primes = [i for i, is_p in enumerate(sieve) if is_p] return primes def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 w = 2 while i * i <= n: if n % i == 0: return False i += w w = 6 - w return True def count_squarefree(L, R): primes = sieve(10**6) count = 0 for x in range(L, R + 1): if x == 0: continue if x == 1: count += 1 continue square_free = True for p in primes: p_sq = p * p if p_sq > x: break if x % p_sq == 0: square_free = False break if not square_free: continue s = math.isqrt(x) if s * s != x: count += 1 else: if s == 1: count += 1 else: if not is_prime(s): pass else: pass return count # Read input L, R = map(int, input().split()) print(count_squarefree(L, R))