結果

問題 No.732 3PrimeCounting
ユーザー vwxyzvwxyz
提出日時 2022-10-03 02:42:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,717 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 101,428 KB
最終ジャッジ日時 2023-08-26 23:58:23
合計ジャッジ時間 38,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,204 KB
testcase_01 AC 92 ms
71,740 KB
testcase_02 AC 89 ms
71,728 KB
testcase_03 AC 92 ms
71,588 KB
testcase_04 AC 89 ms
71,804 KB
testcase_05 AC 89 ms
71,792 KB
testcase_06 AC 90 ms
71,684 KB
testcase_07 AC 91 ms
71,660 KB
testcase_08 AC 92 ms
71,828 KB
testcase_09 AC 90 ms
71,760 KB
testcase_10 AC 91 ms
71,808 KB
testcase_11 AC 89 ms
71,440 KB
testcase_12 AC 91 ms
71,712 KB
testcase_13 AC 90 ms
71,728 KB
testcase_14 AC 91 ms
71,692 KB
testcase_15 AC 89 ms
71,680 KB
testcase_16 AC 88 ms
71,772 KB
testcase_17 AC 88 ms
71,652 KB
testcase_18 AC 88 ms
71,824 KB
testcase_19 AC 91 ms
71,444 KB
testcase_20 AC 105 ms
77,504 KB
testcase_21 AC 120 ms
77,652 KB
testcase_22 AC 120 ms
77,712 KB
testcase_23 AC 101 ms
77,688 KB
testcase_24 AC 100 ms
77,396 KB
testcase_25 AC 130 ms
78,248 KB
testcase_26 AC 124 ms
78,160 KB
testcase_27 AC 107 ms
77,912 KB
testcase_28 AC 109 ms
77,624 KB
testcase_29 AC 117 ms
77,792 KB
testcase_30 AC 115 ms
78,152 KB
testcase_31 AC 120 ms
77,748 KB
testcase_32 AC 127 ms
77,884 KB
testcase_33 AC 129 ms
78,320 KB
testcase_34 AC 128 ms
78,160 KB
testcase_35 AC 120 ms
77,868 KB
testcase_36 AC 121 ms
78,020 KB
testcase_37 AC 103 ms
77,228 KB
testcase_38 AC 104 ms
77,428 KB
testcase_39 AC 129 ms
78,188 KB
testcase_40 AC 121 ms
77,844 KB
testcase_41 AC 121 ms
77,840 KB
testcase_42 AC 120 ms
78,148 KB
testcase_43 AC 117 ms
77,528 KB
testcase_44 AC 117 ms
78,028 KB
testcase_45 AC 108 ms
77,636 KB
testcase_46 AC 108 ms
77,336 KB
testcase_47 AC 113 ms
77,832 KB
testcase_48 AC 135 ms
77,740 KB
testcase_49 AC 138 ms
77,920 KB
testcase_50 AC 119 ms
78,180 KB
testcase_51 AC 121 ms
77,984 KB
testcase_52 AC 112 ms
77,476 KB
testcase_53 AC 196 ms
78,788 KB
testcase_54 AC 2,179 ms
94,204 KB
testcase_55 AC 2,241 ms
94,728 KB
testcase_56 AC 2,186 ms
94,568 KB
testcase_57 AC 379 ms
81,628 KB
testcase_58 AC 379 ms
81,208 KB
testcase_59 AC 205 ms
79,160 KB
testcase_60 AC 472 ms
82,260 KB
testcase_61 AC 473 ms
82,520 KB
testcase_62 TLE -
testcase_63 AC 1,184 ms
86,208 KB
testcase_64 AC 704 ms
83,212 KB
testcase_65 AC 702 ms
83,108 KB
testcase_66 AC 98 ms
77,124 KB
testcase_67 AC 99 ms
77,028 KB
testcase_68 AC 2,578 ms
96,644 KB
testcase_69 AC 2,593 ms
96,656 KB
testcase_70 AC 2,288 ms
94,616 KB
testcase_71 AC 1,934 ms
94,528 KB
testcase_72 AC 938 ms
85,064 KB
testcase_73 TLE -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

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=defaultdict(int)
le=len(primes)
ans=0
for b in range(le-1,-1,-1):
    for a in range(b-1,-1,-1):
        ans+=cnt[primes[a]+primes[b]]
    for p in P.primes:
        if p-primes[b]<=1:
            continue
        if p-primes[b]>=2*primes[b]:
            break
        cnt[p-primes[b]]+=1
print(ans)
0