結果
| 問題 | No.1383 Numbers of Product |
| コンテスト | |
| ユーザー |
Kazun
|
| 提出日時 | 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 None
if cond(R):
return R
if Integer:
L-=1
while R-L>1:
C=L+(R-L)//2
if cond(C):
L=C
else:
R=C
return L
else:
while (R-L)>=ep and Times:
Times-=1
C=L+(R-L)/2
if cond(C):
L=C
else:
R=C
return L
def Floor_Root(a,k):
"""floor(a^(1/k)) を求める.
a:非負整数
k:正の整数
"""
assert 0<=a and 0<k
if a==0:
return 0
if k==1:
return a
#大体の値を求める.
x=int(pow(a,1/k))
#増やす
while pow(x+1,k)<=a:
x+=1
#減らす
while pow(x,k)>a:
x-=1
return x
#================================================
def f(x):
D=K*K+4*x
R=Floor_Root(D,2)
if R**2!=D:
return None
b=-K+R
if b%2==1:
return None
else:
return b//2
#================================================
from collections import defaultdict
N,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=1
while a*(a+K)*(a+2*K)<=N:
p=a*(a+K)*(a+2*K)
F[p]+=1
q=a+3*K
while p*q<=N:
p*=q
F[p]+=1
q+=K
a+=1
if M>=2:
Ans=0
for n in F:
b=0
t=f(n)
if t!=None and 1<=t<=alpha:
b=1
if F[n]+b==M:
Ans+=1
else:
Ans=0
beta=alpha
for n in F:
if F[n]==1:
t=f(n)
if t==None or not(1<=t<=alpha):
Ans+=1
else:
beta-=1
else:
t=f(n)
if t!=None and 1<=t<=alpha:
beta-=1
Ans+=beta
print(Ans)
Kazun