結果
問題 | No.1383 Numbers of Product |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-07 23:06:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 866 ms / 2,000 ms |
コード長 | 2,331 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 82,728 KB |
実行使用メモリ | 168,540 KB |
最終ジャッジ日時 | 2024-11-22 23:24:15 |
合計ジャッジ時間 | 21,273 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 51 |
ソースコード
#================================================def General_Binary_Decrease_Search(L,R,cond,Integer=True,ep=1/(1<<20),Times=50):"""条件式が単調減少であるとき,一般的な二部探索を行う.L:解の下限R:解の上限cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)Integer:解を整数に制限するか?ep:Integer=Falseのとき,解の許容する誤差"""if not(cond(L)):return Noneif cond(R):return Rif Integer:L-=1while R-L>1:C=L+(R-L)//2if cond(C):L=Celse:R=Creturn Lelse:while (R-L)>=ep and Times:Times-=1C=L+(R-L)/2if cond(C):L=Celse:R=Creturn Ldef Floor_Root(a,k):"""floor(a^(1/k)) を求める.a:非負整数k:正の整数"""assert 0<=a and 0<kif a==0:return 0if k==1:return a#大体の値を求める.x=int(pow(a,1/k))#増やすwhile pow(x+1,k)<=a:x+=1#減らすwhile pow(x,k)>a:x-=1return x#================================================def f(x):D=K*K+4*xR=Floor_Root(D,2)if R**2!=D:return Noneb=-K+Rif b%2==1:return Noneelse:return b//2#================================================from collections import defaultdictN,K,M=map(int,input().split())#B=1の解の範囲を求める.alpha=General_Binary_Decrease_Search(0,N,lambda x:x*(x+K)<=N)#B>=2の解を求める.F=defaultdict(int)a=1while a*(a+K)*(a+2*K)<=N:p=a*(a+K)*(a+2*K)F[p]+=1q=a+3*Kwhile p*q<=N:p*=qF[p]+=1q+=Ka+=1if M>=2:Ans=0for n in F:b=0t=f(n)if t!=None and 1<=t<=alpha:b=1if F[n]+b==M:Ans+=1else:Ans=0beta=alphafor n in F:if F[n]==1:t=f(n)if t==None or not(1<=t<=alpha):Ans+=1else:beta-=1else:t=f(n)if t!=None and 1<=t<=alpha:beta-=1Ans+=betaprint(Ans)