結果

問題 No.732 3PrimeCounting
ユーザー vwxyzvwxyz
提出日時 2022-10-03 03:06:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 775 ms / 3,000 ms
コード長 2,820 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 83,384 KB
最終ジャッジ日時 2023-08-27 00:19:06
合計ジャッジ時間 18,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,908 KB
testcase_01 AC 73 ms
71,592 KB
testcase_02 AC 73 ms
71,664 KB
testcase_03 AC 72 ms
71,448 KB
testcase_04 AC 76 ms
71,832 KB
testcase_05 AC 72 ms
71,624 KB
testcase_06 AC 73 ms
71,420 KB
testcase_07 AC 73 ms
71,776 KB
testcase_08 AC 72 ms
71,572 KB
testcase_09 AC 73 ms
71,424 KB
testcase_10 AC 74 ms
71,844 KB
testcase_11 AC 73 ms
71,696 KB
testcase_12 AC 72 ms
71,800 KB
testcase_13 AC 72 ms
71,512 KB
testcase_14 AC 74 ms
71,712 KB
testcase_15 AC 72 ms
71,508 KB
testcase_16 AC 72 ms
71,648 KB
testcase_17 AC 72 ms
71,844 KB
testcase_18 AC 72 ms
71,448 KB
testcase_19 AC 71 ms
71,892 KB
testcase_20 AC 81 ms
76,756 KB
testcase_21 AC 87 ms
77,140 KB
testcase_22 AC 87 ms
77,092 KB
testcase_23 AC 77 ms
76,404 KB
testcase_24 AC 78 ms
76,540 KB
testcase_25 AC 97 ms
77,188 KB
testcase_26 AC 90 ms
77,316 KB
testcase_27 AC 83 ms
76,888 KB
testcase_28 AC 84 ms
76,804 KB
testcase_29 AC 88 ms
77,212 KB
testcase_30 AC 87 ms
77,120 KB
testcase_31 AC 90 ms
76,968 KB
testcase_32 AC 91 ms
77,240 KB
testcase_33 AC 91 ms
77,124 KB
testcase_34 AC 92 ms
77,020 KB
testcase_35 AC 90 ms
77,164 KB
testcase_36 AC 89 ms
77,360 KB
testcase_37 AC 81 ms
76,640 KB
testcase_38 AC 81 ms
76,520 KB
testcase_39 AC 92 ms
77,188 KB
testcase_40 AC 91 ms
77,044 KB
testcase_41 AC 92 ms
77,176 KB
testcase_42 AC 89 ms
77,016 KB
testcase_43 AC 90 ms
77,208 KB
testcase_44 AC 90 ms
77,196 KB
testcase_45 AC 87 ms
76,920 KB
testcase_46 AC 87 ms
76,964 KB
testcase_47 AC 88 ms
77,012 KB
testcase_48 AC 98 ms
77,552 KB
testcase_49 AC 103 ms
77,768 KB
testcase_50 AC 90 ms
76,988 KB
testcase_51 AC 88 ms
76,976 KB
testcase_52 AC 85 ms
76,776 KB
testcase_53 AC 105 ms
78,068 KB
testcase_54 AC 322 ms
80,232 KB
testcase_55 AC 318 ms
80,236 KB
testcase_56 AC 316 ms
80,276 KB
testcase_57 AC 134 ms
78,592 KB
testcase_58 AC 133 ms
78,668 KB
testcase_59 AC 107 ms
78,212 KB
testcase_60 AC 157 ms
79,012 KB
testcase_61 AC 157 ms
79,060 KB
testcase_62 AC 398 ms
80,684 KB
testcase_63 AC 215 ms
79,392 KB
testcase_64 AC 175 ms
79,252 KB
testcase_65 AC 174 ms
79,000 KB
testcase_66 AC 73 ms
71,708 KB
testcase_67 AC 74 ms
71,720 KB
testcase_68 AC 354 ms
80,600 KB
testcase_69 AC 350 ms
80,652 KB
testcase_70 AC 326 ms
80,144 KB
testcase_71 AC 324 ms
80,140 KB
testcase_72 AC 210 ms
79,408 KB
testcase_73 AC 599 ms
82,592 KB
testcase_74 AC 596 ms
82,592 KB
testcase_75 AC 91 ms
77,216 KB
testcase_76 AC 346 ms
80,512 KB
testcase_77 AC 138 ms
78,684 KB
testcase_78 AC 474 ms
81,348 KB
testcase_79 AC 356 ms
80,476 KB
testcase_80 AC 437 ms
81,532 KB
testcase_81 AC 326 ms
80,328 KB
testcase_82 AC 83 ms
76,740 KB
testcase_83 AC 135 ms
78,508 KB
testcase_84 AC 141 ms
78,864 KB
testcase_85 AC 287 ms
79,972 KB
testcase_86 AC 441 ms
81,240 KB
testcase_87 AC 772 ms
83,356 KB
testcase_88 AC 775 ms
83,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Prime:
    def __init__(self,N):
        assert N<=10**8
        self.smallest_prime_factor=[None]*(N+1)
        for i in range(2,N+1,2):
            self.smallest_prime_factor[i]=2
        n=int(N**.5)+1
        for p in range(3,n,2):
            if self.smallest_prime_factor[p]==None:
                self.smallest_prime_factor[p]=p
                for i in range(p**2,N+1,2*p):
                    if self.smallest_prime_factor[i]==None:
                        self.smallest_prime_factor[i]=p
        for p in range(n,N+1):
            if self.smallest_prime_factor[p]==None:
                self.smallest_prime_factor[p]=p
        self.primes=[p for p in range(N+1) if p==self.smallest_prime_factor[p]]

    def Factorize(self,N):
        assert N>=1
        factors=defaultdict(int)
        if N<=len(self.smallest_prime_factor)-1:
            while N!=1:
                factors[self.smallest_prime_factor[N]]+=1
                N//=self.smallest_prime_factor[N]
        else:
            for p in self.primes:
                while N%p==0:
                    N//=p
                    factors[p]+=1
                if N<p*p:
                    if N!=1:
                        factors[N]+=1
                    break
                if N<=len(self.smallest_prime_factor)-1:
                    while N!=1:
                        factors[self.smallest_prime_factor[N]]+=1
                        N//=self.smallest_prime_factor[N]
                    break
            else:
                if N!=1:
                    factors[N]+=1
        return factors

    def Divisors(self,N):
        assert N>0
        divisors=[1]
        for p,e in self.Factorize(N).items():
            pow_p=[1]
            for _ in range(e):
                pow_p.append(pow_p[-1]*p)
            divisors=[i*j for i in divisors for j in pow_p]
        return divisors

    def Is_Prime(self,N):
        return N==self.smallest_prime_factor[N]

    def Totient(self,N):
        for p in self.Factorize(N).keys():
            N*=p-1
            N//=p
        return N

    def Mebius(self,N):
        fact=self.Factorize(N)
        for e in fact.values():
            if e>=2:
                return 0
        else:
            if len(fact)%2==0:
                return 1
            else:
                return -1

N=int(input())
P=Prime(3*N)
primes=[p for p in P.primes if p<=N]
cnt=[0]*(3*N+1)
le=len(primes)
ans=0
i=len(P.primes)-1
for b in range(le-1,-1,-1):
    for a in range(b-1,-1,-1):
        ans+=cnt[primes[a]+primes[b]]
    while i and P.primes[i-1]-primes[b]>1:
        i-=1
    for j in range(i,len(P.primes)):
        p=P.primes[j]
        if p-primes[b]>=2*primes[b]:
            break
        if (p-primes[b])%2 and not P.Is_Prime(p-primes[b]-2):
            continue
        cnt[p-primes[b]]+=1
print(ans)
0