結果
問題 | No.732 3PrimeCounting |
ユーザー | vwxyz |
提出日時 | 2022-10-03 03:06:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 735 ms / 3,000 ms |
コード長 | 2,820 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 79,744 KB |
最終ジャッジ日時 | 2024-06-07 19:41:03 |
合計ジャッジ時間 | 13,912 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,224 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | AC | 39 ms
52,776 KB |
testcase_03 | AC | 39 ms
52,480 KB |
testcase_04 | AC | 39 ms
52,096 KB |
testcase_05 | AC | 39 ms
52,864 KB |
testcase_06 | AC | 38 ms
52,352 KB |
testcase_07 | AC | 38 ms
52,480 KB |
testcase_08 | AC | 38 ms
52,480 KB |
testcase_09 | AC | 38 ms
52,608 KB |
testcase_10 | AC | 39 ms
52,352 KB |
testcase_11 | AC | 39 ms
52,736 KB |
testcase_12 | AC | 39 ms
52,608 KB |
testcase_13 | AC | 38 ms
52,608 KB |
testcase_14 | AC | 38 ms
52,096 KB |
testcase_15 | AC | 39 ms
52,224 KB |
testcase_16 | AC | 39 ms
52,352 KB |
testcase_17 | AC | 37 ms
52,096 KB |
testcase_18 | AC | 38 ms
52,480 KB |
testcase_19 | AC | 38 ms
52,608 KB |
testcase_20 | AC | 49 ms
60,800 KB |
testcase_21 | AC | 57 ms
64,768 KB |
testcase_22 | AC | 57 ms
64,384 KB |
testcase_23 | AC | 44 ms
59,008 KB |
testcase_24 | AC | 44 ms
59,520 KB |
testcase_25 | AC | 60 ms
65,664 KB |
testcase_26 | AC | 58 ms
64,640 KB |
testcase_27 | AC | 51 ms
63,104 KB |
testcase_28 | AC | 51 ms
62,336 KB |
testcase_29 | AC | 56 ms
64,512 KB |
testcase_30 | AC | 55 ms
64,384 KB |
testcase_31 | AC | 58 ms
64,896 KB |
testcase_32 | AC | 58 ms
65,152 KB |
testcase_33 | AC | 59 ms
64,384 KB |
testcase_34 | AC | 57 ms
64,384 KB |
testcase_35 | AC | 57 ms
65,024 KB |
testcase_36 | AC | 57 ms
65,024 KB |
testcase_37 | AC | 47 ms
60,416 KB |
testcase_38 | AC | 49 ms
60,800 KB |
testcase_39 | AC | 58 ms
65,024 KB |
testcase_40 | AC | 58 ms
64,256 KB |
testcase_41 | AC | 57 ms
64,256 KB |
testcase_42 | AC | 59 ms
64,384 KB |
testcase_43 | AC | 57 ms
64,256 KB |
testcase_44 | AC | 57 ms
64,896 KB |
testcase_45 | AC | 53 ms
63,360 KB |
testcase_46 | AC | 55 ms
63,360 KB |
testcase_47 | AC | 56 ms
64,128 KB |
testcase_48 | AC | 65 ms
67,072 KB |
testcase_49 | AC | 64 ms
67,200 KB |
testcase_50 | AC | 56 ms
64,512 KB |
testcase_51 | AC | 57 ms
65,024 KB |
testcase_52 | AC | 53 ms
62,336 KB |
testcase_53 | AC | 78 ms
68,480 KB |
testcase_54 | AC | 278 ms
72,832 KB |
testcase_55 | AC | 281 ms
72,960 KB |
testcase_56 | AC | 278 ms
72,960 KB |
testcase_57 | AC | 101 ms
69,248 KB |
testcase_58 | AC | 104 ms
69,760 KB |
testcase_59 | AC | 77 ms
68,728 KB |
testcase_60 | AC | 126 ms
71,680 KB |
testcase_61 | AC | 126 ms
71,296 KB |
testcase_62 | AC | 351 ms
73,728 KB |
testcase_63 | AC | 183 ms
71,168 KB |
testcase_64 | AC | 145 ms
70,836 KB |
testcase_65 | AC | 142 ms
70,784 KB |
testcase_66 | AC | 40 ms
52,992 KB |
testcase_67 | AC | 40 ms
52,608 KB |
testcase_68 | AC | 315 ms
73,600 KB |
testcase_69 | AC | 307 ms
73,344 KB |
testcase_70 | AC | 274 ms
72,960 KB |
testcase_71 | AC | 285 ms
72,576 KB |
testcase_72 | AC | 173 ms
70,784 KB |
testcase_73 | AC | 540 ms
79,520 KB |
testcase_74 | AC | 538 ms
79,744 KB |
testcase_75 | AC | 62 ms
65,664 KB |
testcase_76 | AC | 297 ms
72,960 KB |
testcase_77 | AC | 107 ms
69,888 KB |
testcase_78 | AC | 430 ms
74,112 KB |
testcase_79 | AC | 308 ms
72,832 KB |
testcase_80 | AC | 396 ms
77,056 KB |
testcase_81 | AC | 286 ms
72,448 KB |
testcase_82 | AC | 52 ms
62,208 KB |
testcase_83 | AC | 106 ms
70,656 KB |
testcase_84 | AC | 110 ms
71,296 KB |
testcase_85 | AC | 247 ms
72,192 KB |
testcase_86 | AC | 406 ms
74,496 KB |
testcase_87 | AC | 724 ms
76,544 KB |
testcase_88 | AC | 735 ms
77,056 KB |
ソースコード
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)