結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,896 KB
testcase_01 AC 175 ms
7,940 KB
testcase_02 AC 171 ms
7,788 KB
testcase_03 AC 195 ms
7,792 KB
testcase_04 AC 172 ms
7,948 KB
testcase_05 AC 172 ms
7,960 KB
testcase_06 AC 144 ms
7,836 KB
testcase_07 AC 144 ms
7,776 KB
testcase_08 AC 144 ms
7,888 KB
testcase_09 AC 149 ms
7,844 KB
testcase_10 AC 143 ms
7,824 KB
testcase_11 AC 174 ms
7,848 KB
testcase_12 AC 176 ms
7,792 KB
testcase_13 AC 175 ms
7,916 KB
testcase_14 AC 176 ms
7,900 KB
testcase_15 AC 182 ms
7,824 KB
testcase_16 AC 114 ms
7,820 KB
testcase_17 AC 113 ms
7,968 KB
testcase_18 AC 113 ms
7,832 KB
testcase_19 AC 114 ms
7,972 KB
testcase_20 AC 112 ms
7,980 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