結果

問題 No.2440 Accuracy of Integer Division Approximate Functions
ユーザー 👑 MizarMizar
提出日時 2023-08-31 11:51:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 255 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 7,988 KB
最終ジャッジ日時 2023-08-31 11:51:49
合計ジャッジ時間 4,969 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 174 ms
7,832 KB
testcase_02 AC 199 ms
7,964 KB
testcase_03 AC 172 ms
7,868 KB
testcase_04 AC 172 ms
7,792 KB
testcase_05 AC 172 ms
7,988 KB
testcase_06 AC 146 ms
7,776 KB
testcase_07 AC 142 ms
7,836 KB
testcase_08 AC 145 ms
7,852 KB
testcase_09 AC 145 ms
7,852 KB
testcase_10 AC 143 ms
7,972 KB
testcase_11 AC 174 ms
7,868 KB
testcase_12 AC 174 ms
7,912 KB
testcase_13 AC 175 ms
7,772 KB
testcase_14 AC 170 ms
7,840 KB
testcase_15 AC 176 ms
7,836 KB
testcase_16 AC 113 ms
7,836 KB
testcase_17 AC 112 ms
7,768 KB
testcase_18 AC 113 ms
7,980 KB
testcase_19 AC 111 ms
7,788 KB
testcase_20 AC 114 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n,m,a):
	b=r=0
	while n>0:r+=a//m*n*(n-1)//2+b//m*n;a%=m;b%=m;y=a*n+b;n,b,m,a=y//m,y%m,a,m
	return r
for _ in range(int(input())):
	n,d,m,s=map(int,input().split());p,q=1<<s,d*m
	if p!=q:n=min(n,d*p//abs(q-p));n-=abs(f(n+1,p,m)-f(n+1,d,1))
	print(n)
0