結果
問題 | No.732 3PrimeCounting |
ユーザー | vwxyz |
提出日時 | 2022-10-03 03:06:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 824 ms / 3,000 ms |
コード長 | 2,820 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 79,616 KB |
最終ジャッジ日時 | 2024-12-26 04:26:33 |
合計ジャッジ時間 | 16,789 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
52,480 KB |
testcase_01 | AC | 52 ms
52,480 KB |
testcase_02 | AC | 49 ms
52,864 KB |
testcase_03 | AC | 49 ms
52,480 KB |
testcase_04 | AC | 51 ms
52,992 KB |
testcase_05 | AC | 50 ms
52,480 KB |
testcase_06 | AC | 48 ms
52,480 KB |
testcase_07 | AC | 49 ms
52,608 KB |
testcase_08 | AC | 43 ms
52,736 KB |
testcase_09 | AC | 46 ms
52,352 KB |
testcase_10 | AC | 45 ms
52,352 KB |
testcase_11 | AC | 44 ms
52,736 KB |
testcase_12 | AC | 44 ms
52,608 KB |
testcase_13 | AC | 43 ms
52,352 KB |
testcase_14 | AC | 45 ms
52,352 KB |
testcase_15 | AC | 43 ms
52,608 KB |
testcase_16 | AC | 46 ms
52,992 KB |
testcase_17 | AC | 47 ms
52,736 KB |
testcase_18 | AC | 45 ms
52,352 KB |
testcase_19 | AC | 47 ms
52,608 KB |
testcase_20 | AC | 61 ms
61,056 KB |
testcase_21 | AC | 70 ms
64,512 KB |
testcase_22 | AC | 68 ms
64,512 KB |
testcase_23 | AC | 50 ms
59,008 KB |
testcase_24 | AC | 50 ms
59,520 KB |
testcase_25 | AC | 72 ms
65,408 KB |
testcase_26 | AC | 69 ms
64,896 KB |
testcase_27 | AC | 66 ms
62,592 KB |
testcase_28 | AC | 65 ms
62,592 KB |
testcase_29 | AC | 74 ms
64,512 KB |
testcase_30 | AC | 68 ms
64,512 KB |
testcase_31 | AC | 79 ms
65,024 KB |
testcase_32 | AC | 71 ms
64,896 KB |
testcase_33 | AC | 70 ms
64,896 KB |
testcase_34 | AC | 72 ms
64,896 KB |
testcase_35 | AC | 75 ms
64,768 KB |
testcase_36 | AC | 67 ms
64,768 KB |
testcase_37 | AC | 58 ms
60,672 KB |
testcase_38 | AC | 52 ms
60,672 KB |
testcase_39 | AC | 68 ms
64,768 KB |
testcase_40 | AC | 66 ms
64,512 KB |
testcase_41 | AC | 67 ms
64,256 KB |
testcase_42 | AC | 68 ms
64,512 KB |
testcase_43 | AC | 66 ms
64,256 KB |
testcase_44 | AC | 72 ms
64,512 KB |
testcase_45 | AC | 68 ms
62,976 KB |
testcase_46 | AC | 66 ms
63,488 KB |
testcase_47 | AC | 70 ms
65,024 KB |
testcase_48 | AC | 77 ms
67,072 KB |
testcase_49 | AC | 80 ms
67,072 KB |
testcase_50 | AC | 63 ms
64,768 KB |
testcase_51 | AC | 66 ms
64,512 KB |
testcase_52 | AC | 62 ms
63,104 KB |
testcase_53 | AC | 84 ms
68,352 KB |
testcase_54 | AC | 305 ms
72,704 KB |
testcase_55 | AC | 312 ms
72,448 KB |
testcase_56 | AC | 302 ms
72,704 KB |
testcase_57 | AC | 116 ms
69,248 KB |
testcase_58 | AC | 116 ms
69,504 KB |
testcase_59 | AC | 93 ms
68,480 KB |
testcase_60 | AC | 154 ms
71,808 KB |
testcase_61 | AC | 143 ms
71,296 KB |
testcase_62 | AC | 396 ms
73,216 KB |
testcase_63 | AC | 198 ms
71,040 KB |
testcase_64 | AC | 169 ms
70,656 KB |
testcase_65 | AC | 162 ms
71,040 KB |
testcase_66 | AC | 43 ms
52,864 KB |
testcase_67 | AC | 42 ms
52,864 KB |
testcase_68 | AC | 361 ms
73,088 KB |
testcase_69 | AC | 358 ms
73,088 KB |
testcase_70 | AC | 322 ms
72,704 KB |
testcase_71 | AC | 341 ms
72,704 KB |
testcase_72 | AC | 202 ms
71,168 KB |
testcase_73 | AC | 620 ms
79,488 KB |
testcase_74 | AC | 604 ms
79,616 KB |
testcase_75 | AC | 73 ms
65,408 KB |
testcase_76 | AC | 349 ms
73,728 KB |
testcase_77 | AC | 117 ms
69,888 KB |
testcase_78 | AC | 508 ms
74,368 KB |
testcase_79 | AC | 351 ms
73,216 KB |
testcase_80 | AC | 445 ms
77,184 KB |
testcase_81 | AC | 317 ms
72,832 KB |
testcase_82 | AC | 60 ms
61,824 KB |
testcase_83 | AC | 113 ms
70,528 KB |
testcase_84 | AC | 122 ms
71,424 KB |
testcase_85 | AC | 279 ms
72,320 KB |
testcase_86 | AC | 436 ms
74,112 KB |
testcase_87 | AC | 824 ms
77,184 KB |
testcase_88 | AC | 818 ms
76,800 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)