結果
問題 | No.1661 Sum is Prime (Hard Version) |
ユーザー | 👑 Kazun |
提出日時 | 2021-08-27 21:58:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,019 ms / 3,000 ms |
コード長 | 953 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 82,176 KB |
最終ジャッジ日時 | 2024-05-01 02:30:20 |
合計ジャッジ時間 | 9,722 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,608 KB |
testcase_01 | AC | 33 ms
52,608 KB |
testcase_02 | AC | 715 ms
81,792 KB |
testcase_03 | AC | 33 ms
52,608 KB |
testcase_04 | AC | 33 ms
52,864 KB |
testcase_05 | AC | 33 ms
52,864 KB |
testcase_06 | AC | 38 ms
59,264 KB |
testcase_07 | AC | 37 ms
53,120 KB |
testcase_08 | AC | 39 ms
59,516 KB |
testcase_09 | AC | 42 ms
59,264 KB |
testcase_10 | AC | 46 ms
61,312 KB |
testcase_11 | AC | 43 ms
60,544 KB |
testcase_12 | AC | 566 ms
81,464 KB |
testcase_13 | AC | 545 ms
81,408 KB |
testcase_14 | AC | 618 ms
81,700 KB |
testcase_15 | AC | 833 ms
81,664 KB |
testcase_16 | AC | 689 ms
82,048 KB |
testcase_17 | AC | 606 ms
82,000 KB |
testcase_18 | AC | 278 ms
75,776 KB |
testcase_19 | AC | 456 ms
79,780 KB |
testcase_20 | AC | 301 ms
75,904 KB |
testcase_21 | AC | 537 ms
78,080 KB |
testcase_22 | AC | 1,019 ms
82,040 KB |
testcase_23 | AC | 964 ms
82,176 KB |
ソースコード
#Thanks for https://judge.yosupo.jp/submission/33263 from math import sqrt def prime_counting(n): if n<=1: return 0 n2 = int(n ** 0.5) ndn2 = int(n / n2) hl = [0] * ndn2 for i in range(1, ndn2): hl[i] = int(n / i) - 1 hs = list(range(-1, n2)) pi = 0 for x in range(2, n2 + 1): if hs[x] == hs[x - 1]: continue x2 = x * x imax = min(ndn2, int(n / x2) + 1) ix = x for i in range(1, imax): if ix < ndn2: hl[i] -= hl[ix] else: hl[i] -= hs[int(n / ix)] hl[i] += pi ix += x for k in range(n2, x2 - 1, -1): hs[k] -= hs[int(k / x)] - pi pi += 1 return hl[1] #================================================== L,R=map(int,input().split()) alpha=prime_counting(R)-prime_counting(L-1) beta =prime_counting(2*R)-prime_counting(2*L) print(alpha+beta)