結果

問題 No.1657 Sum is Prime (Easy Version)
コンテスト
ユーザー neterukun
提出日時 2021-08-27 21:36:35
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 536 ms / 2,000 ms
+ 170µs
コード長 524 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 68 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 84,380 KB
最終ジャッジ日時 2026-09-27 07:17:30
合計ジャッジ時間 5,476 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def is_prime(x):
    if x == 2:
        return True
    if x == 1 or x % 2 == 0:
        return False
    for k in range(3, int(x ** 0.5) + 1, 2):
        if x % k == 0:
            return False
    return True


l, r = map(int, input().split())


ans = 0
for i in range(1, 10 ** 6 + 1):
    a = i
    b = i + 1
    if l <= a <= r and l <= b <= r:
        ab = a + b
        if is_prime(ab):
            ans += 1
    a = i
    b = i
    if l <= a <= r and l <= b <= r:
        if is_prime(a):
            ans += 1
print(ans)
0