結果
問題 | No.1661 Sum is Prime (Hard Version) |
ユーザー | 👑 rin204 |
提出日時 | 2022-01-25 18:55:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 501 ms / 3,000 ms |
コード長 | 1,558 bytes |
コンパイル時間 | 475 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 87,296 KB |
最終ジャッジ日時 | 2024-12-30 17:00:49 |
合計ジャッジ時間 | 6,600 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
52,224 KB |
testcase_01 | AC | 47 ms
52,224 KB |
testcase_02 | AC | 409 ms
82,996 KB |
testcase_03 | AC | 51 ms
51,840 KB |
testcase_04 | AC | 48 ms
52,352 KB |
testcase_05 | AC | 51 ms
52,352 KB |
testcase_06 | AC | 51 ms
52,736 KB |
testcase_07 | AC | 47 ms
52,480 KB |
testcase_08 | AC | 49 ms
52,736 KB |
testcase_09 | AC | 52 ms
52,480 KB |
testcase_10 | AC | 49 ms
52,736 KB |
testcase_11 | AC | 49 ms
52,736 KB |
testcase_12 | AC | 293 ms
82,412 KB |
testcase_13 | AC | 289 ms
82,280 KB |
testcase_14 | AC | 345 ms
84,224 KB |
testcase_15 | AC | 366 ms
83,856 KB |
testcase_16 | AC | 327 ms
83,308 KB |
testcase_17 | AC | 313 ms
83,164 KB |
testcase_18 | AC | 220 ms
80,128 KB |
testcase_19 | AC | 310 ms
81,280 KB |
testcase_20 | AC | 233 ms
79,616 KB |
testcase_21 | AC | 302 ms
81,792 KB |
testcase_22 | AC | 501 ms
87,296 KB |
testcase_23 | AC | 411 ms
87,168 KB |
testcase_24 | AC | 352 ms
84,360 KB |
ソースコード
# https://judge.yosupo.jp/submission/69031 def count_primes(n): if n < 2: return 0 v = int(n ** 0.5) + 1 smalls = [i // 2 for i in range(1, v + 1)] smalls[1] = 0 s = v // 2 roughs = [2 * i + 1 for i in range(s)] larges = [(n // (2 * i + 1) + 1) // 2 for i in range(s)] skip = [False] * v pc = 0 for p in range(3, v): if smalls[p] <= smalls[p - 1]: continue q = p * p pc += 1 if q * q > n: break skip[p] = True for i in range(q, v, 2 * p): skip[i] = True ns = 0 for k in range(s): i = roughs[k] if skip[i]: continue d = i * p larges[ns] = larges[k] - \ (larges[smalls[d] - pc] if d < v else smalls[n // d]) + pc roughs[ns] = i ns += 1 s = ns for j in range((v - 1) // p, p - 1, -1): c = smalls[j] - pc e = min((j + 1) * p, v) for i in range(j * p, e): smalls[i] -= c for k in range(1, s): m = n // roughs[k] s = larges[k] - (pc + k - 1) for l in range(1, k): p = roughs[l] if p * p > m: break s -= smalls[m // p] - (pc + l - 1) larges[0] -= s return larges[0] l, r = map(int, input().split()) if l == r == 1: print(0) exit() ans = count_primes(r) - count_primes(l - 1) ans += count_primes(2 * r - 1) - count_primes(2 * l) print(ans)