結果

問題 No.843 Triple Primes
ユーザー tails1434
提出日時 2020-01-06 07:42:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 78,644 KB
最終ジャッジ日時 2024-11-22 23:48:06
合計ジャッジ時間 12,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def main():
    N = int(input())
    primes = []
    for i in range(1, N + 1):
        if is_prime(i):
            primes.append(i)

    ans = 0
    for prime in primes:
        tmp = (2 + prime) ** 0.5
        if tmp.is_integer() and is_prime(tmp):
            if tmp == 2:
                ans += 1
            else:
                ans += 2


    print(ans)


if __name__ == "__main__":
    main()
0