結果

問題 No.2440 Accuracy of Integer Division Approximate Functions
ユーザー 👑 kmjpkmjp
提出日時 2023-08-29 00:14:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 512 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,484 KB
最終ジャッジ日時 2023-08-29 00:14:57
合計ジャッジ時間 5,002 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 121 ms
8,284 KB
testcase_17 AC 119 ms
8,164 KB
testcase_18 AC 118 ms
8,108 KB
testcase_19 AC 120 ms
8,280 KB
testcase_20 AC 119 ms
8,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def floor_sum(N,M,A,B):
	# sum(i=0...N-1) floor((A*i+B)/M)
	
	ret=0
	if B>=M:
		ret+=N*(B//M)
		B%=M;

	if A>=M:
		ret+=N*(N-1)//2*(A//M)
		A%=M
	
	Y=(A*N+B)//M
	if Y==0:
		return ret
	
	X=Y*M-B
	ret+=(N-(X+A-1)//A)*Y
	ret+=floor_sum(Y,A,M,(A-X%A)%A)
	return ret



T=int(input())
while T > 0:
	T-=1
	N,D,M,S=map(int,input().strip().split(" "))
	
	a=D*M
	b=1<<S
	
	if a==b:
		R=N
	else:
		R=min(N,D*b//abs(a-b))
		C=floor_sum(R+1,D,1,0)-floor_sum(R+1,b,M,0)
		C=abs(C)

	print(abs(R-C))

0