結果

問題 No.843 Triple Primes
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-01-10 22:29:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,336 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 110,212 KB
最終ジャッジ日時 2024-01-10 22:29:54
合計ジャッジ時間 8,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
97,028 KB
testcase_01 AC 149 ms
110,212 KB
testcase_02 AC 129 ms
99,716 KB
testcase_03 AC 128 ms
99,716 KB
testcase_04 AC 128 ms
99,716 KB
testcase_05 AC 128 ms
99,716 KB
testcase_06 AC 125 ms
99,844 KB
testcase_07 AC 150 ms
107,524 KB
testcase_08 AC 144 ms
108,804 KB
testcase_09 AC 144 ms
110,212 KB
testcase_10 AC 139 ms
107,524 KB
testcase_11 AC 142 ms
108,804 KB
testcase_12 AC 147 ms
110,084 KB
testcase_13 AC 144 ms
108,932 KB
testcase_14 AC 140 ms
108,804 KB
testcase_15 AC 159 ms
107,524 KB
testcase_16 AC 134 ms
107,652 KB
testcase_17 AC 104 ms
97,028 KB
testcase_18 AC 108 ms
97,028 KB
testcase_19 AC 107 ms
97,028 KB
testcase_20 AC 135 ms
101,508 KB
testcase_21 AC 127 ms
99,716 KB
testcase_22 AC 131 ms
104,580 KB
testcase_23 AC 134 ms
105,348 KB
testcase_24 AC 135 ms
101,508 KB
testcase_25 AC 133 ms
100,612 KB
testcase_26 AC 141 ms
110,212 KB
testcase_27 AC 132 ms
99,716 KB
testcase_28 AC 145 ms
108,932 KB
testcase_29 AC 133 ms
101,892 KB
testcase_30 AC 140 ms
110,212 KB
testcase_31 AC 129 ms
99,716 KB
testcase_32 AC 136 ms
99,844 KB
testcase_33 AC 137 ms
102,020 KB
testcase_34 AC 136 ms
104,580 KB
testcase_35 AC 143 ms
110,212 KB
testcase_36 AC 132 ms
100,356 KB
testcase_37 AC 146 ms
107,524 KB
testcase_38 AC 141 ms
105,476 KB
testcase_39 AC 156 ms
110,084 KB
testcase_40 AC 117 ms
97,028 KB
testcase_41 AC 109 ms
97,028 KB
testcase_42 AC 146 ms
108,676 KB
testcase_43 AC 145 ms
108,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline


class prime_factorize():
    
    def __init__(self,M=10**6):
        self.sieve = [-1]*(M+1)
        self.sieve[1] = 1
        self.p = [False]*(M+1)
        self.mu = [1]*(M+1)
        
        for i in range(2,M+1):
            if self.sieve[i] == -1:
                self.p[i] = True
                
                i2 = i**2
                for j in range(i2,M+1,i2):
                    
                    self.mu[j] = 0
                
                
                for j in range(i,M+1,i):
                    self.sieve[j] = i
                    
                    self.mu[j] *= -1
                    
    def factors(self,x):
        tmp = []
        while self.sieve[x] != x:
            tmp.append(self.sieve[x])
            x //= self.sieve[x]
        tmp.append(self.sieve[x])
        return tmp
        
    def is_prime(self,x):
        return self.p[x]
        
    def mobius(self,x):
        return self.mu[x]

N = int(input())
pf = prime_factorize()
ans = 0
S = set()
P = set()
for i in range(2,N+1):
    if pf.is_prime(i):
        P.add(i)
        S.add(i**2)

if N==1:
    print(0)
    exit()
p = 2
for q in P:
    if (q+2) in S:
        ans += 1
print(ans*2 - 1)
0