結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | wolgnik |
提出日時 | 2021-08-27 21:32:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 281 ms / 2,000 ms |
コード長 | 1,392 bytes |
コンパイル時間 | 290 ms |
コンパイル使用メモリ | 87,076 KB |
実行使用メモリ | 108,696 KB |
最終ジャッジ日時 | 2023-08-13 08:06:15 |
合計ジャッジ時間 | 5,006 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
71,412 KB |
testcase_01 | AC | 72 ms
71,356 KB |
testcase_02 | AC | 281 ms
107,796 KB |
testcase_03 | AC | 71 ms
71,548 KB |
testcase_04 | AC | 71 ms
71,388 KB |
testcase_05 | AC | 70 ms
71,392 KB |
testcase_06 | AC | 92 ms
76,688 KB |
testcase_07 | AC | 85 ms
76,652 KB |
testcase_08 | AC | 91 ms
76,728 KB |
testcase_09 | AC | 90 ms
76,540 KB |
testcase_10 | AC | 90 ms
76,600 KB |
testcase_11 | AC | 89 ms
76,992 KB |
testcase_12 | AC | 263 ms
107,232 KB |
testcase_13 | AC | 164 ms
92,988 KB |
testcase_14 | AC | 230 ms
103,060 KB |
testcase_15 | AC | 247 ms
103,408 KB |
testcase_16 | AC | 133 ms
88,236 KB |
testcase_17 | AC | 141 ms
90,180 KB |
testcase_18 | AC | 144 ms
91,968 KB |
testcase_19 | AC | 237 ms
104,724 KB |
testcase_20 | AC | 170 ms
96,400 KB |
testcase_21 | AC | 266 ms
108,496 KB |
testcase_22 | AC | 268 ms
108,508 KB |
testcase_23 | AC | 271 ms
108,696 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)