結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | wolgnik |
提出日時 | 2021-08-27 21:32:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 1,392 bytes |
コンパイル時間 | 306 ms |
コンパイル使用メモリ | 82,388 KB |
実行使用メモリ | 107,264 KB |
最終ジャッジ日時 | 2024-05-01 01:47:17 |
合計ジャッジ時間 | 4,021 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,972 KB |
testcase_01 | AC | 37 ms
53,300 KB |
testcase_02 | AC | 244 ms
106,600 KB |
testcase_03 | AC | 37 ms
53,300 KB |
testcase_04 | AC | 36 ms
53,432 KB |
testcase_05 | AC | 37 ms
52,900 KB |
testcase_06 | AC | 59 ms
67,672 KB |
testcase_07 | AC | 51 ms
63,100 KB |
testcase_08 | AC | 56 ms
66,832 KB |
testcase_09 | AC | 58 ms
67,644 KB |
testcase_10 | AC | 57 ms
68,316 KB |
testcase_11 | AC | 57 ms
67,808 KB |
testcase_12 | AC | 217 ms
105,944 KB |
testcase_13 | AC | 127 ms
88,940 KB |
testcase_14 | AC | 186 ms
101,864 KB |
testcase_15 | AC | 199 ms
101,960 KB |
testcase_16 | AC | 105 ms
83,744 KB |
testcase_17 | AC | 108 ms
86,800 KB |
testcase_18 | AC | 119 ms
87,772 KB |
testcase_19 | AC | 209 ms
103,636 KB |
testcase_20 | AC | 154 ms
93,332 KB |
testcase_21 | AC | 241 ms
105,388 KB |
testcase_22 | AC | 229 ms
105,168 KB |
testcase_23 | AC | 241 ms
107,264 KB |
ソースコード
import sys input = sys.stdin.readline L, R = map(int, input().split()) class sieve: def __init__(self, n): self.n = n self.sv = [1] * (n + 1) self.sv[0] = 0 self.sv[1] = 0 self.minp = [n] * (n + 1) for i in range(2, n + 1): if self.sv[i]: self.minp[i] = i for j in range(i * 2, n + 1, i): self.sv[j] = 0 self.minp[j] = min(self.minp[j], i) def isprime(self, x): if x > self.n: return False return self.sv[x] == 1 def factorize(self, x): if self.sv[x]: return [(x, 1)] res = [] while x > 1: p = self.minp[x] c = 0 while x % p == 0: x //= p c += 1 res.append((p, c)) return res def modlcm(self, a, mod): res = [0] * (self.n + 1) ex = set() for i in range(len(a)): f = self.factorize(a[i]) for j in f: if j > self.n: ex.add(j) continue res[j] = max(f.count(j), res[j]) rres = 1 for i in range(self.n + 1): if res[i] != 0: rres *= pow(i, res[i], mod) rres %= mod for i in ex: rres *= i rres %= mod return rres sv = sieve(R * 2) res = 0 for p in range(R * 2 + 1): if sv.isprime(p): if p in range(L, R + 1): res += 1 x = (p - 1) // 2 y = -((1 - p) // 2) if x in range(L, R + 1) and y in range(L, R + 1): res += 1 print(res)