結果

問題 No.3398 Accuracy of Integer Division Approximate Function 2
コンテスト
ユーザー Mizar
提出日時 2025-12-06 02:48:22
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 221 ms / 2,000 ms
+ 482µs
コード長 357 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 238 ms
コンパイル使用メモリ 95,964 KB
実行使用メモリ 85,200 KB
最終ジャッジ日時 2026-07-18 23:27:57
合計ジャッジ時間 4,427 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math
for _ in[0]*int(input()):
 D,A,B,K=map(int,input().split());g=math.gcd(D,A);l,h=0,A*B*K+2
 if A*B%D<1 and D*K+g>=A:D,l,h=1,-1,0
 while l+1<h:
  x=n=(l+h)//2;a,b,c,m=B,-(A*B//D),D,A;s=v=d=0
  while(n):a+=c//m*b;c%=m;s+=d//m*b;d%=m;v=max(v,s,s+a*~-n+b*(n:=(c*~-n+d)//m));s+=(a+b)*(a<0);a,b,c,d,m=b,a,m,m+~d,c
  if v<=B*K:l=x
  else:h=x
 print(D*l)
0