結果

問題 No.2440 Accuracy of Integer Division Approximate Functions
ユーザー 👑 NachiaNachia
提出日時 2023-08-24 21:16:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 7,964 KB
最終ジャッジ日時 2023-08-24 21:17:02
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,852 KB
testcase_01 AC 179 ms
7,784 KB
testcase_02 AC 174 ms
7,836 KB
testcase_03 AC 176 ms
7,860 KB
testcase_04 AC 170 ms
7,784 KB
testcase_05 AC 177 ms
7,928 KB
testcase_06 AC 144 ms
7,964 KB
testcase_07 AC 145 ms
7,856 KB
testcase_08 AC 147 ms
7,856 KB
testcase_09 AC 144 ms
7,888 KB
testcase_10 AC 146 ms
7,912 KB
testcase_11 AC 204 ms
7,836 KB
testcase_12 AC 177 ms
7,948 KB
testcase_13 AC 176 ms
7,820 KB
testcase_14 AC 175 ms
7,864 KB
testcase_15 AC 177 ms
7,872 KB
testcase_16 AC 117 ms
7,796 KB
testcase_17 AC 117 ms
7,936 KB
testcase_18 AC 119 ms
7,864 KB
testcase_19 AC 116 ms
7,792 KB
testcase_20 AC 114 ms
7,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def floorsum(n,m,a,b) :
    if a == 0 :
        return b//m * n
    ans = 0
    while n != 0 :
        if a >= m :
            ans += a // m * (n * (n-1) // 2)
            a %= m
        if b >= m :
            ans += b // m * n
            b %= m
        yx = a * n + b
        if yx < m :
            return ans
        n = yx // m
        b = yx % m
        yx = a
        a = m
        m = yx
    return ans

q = int(input())
for i in range(q) :
    n,d,m,s = map(int, input().split())
    s = 2 ** s
    dif = abs(s - m*d)
    if dif == 0 :
        print(n, flush=False)
        continue
    n = min(n, d*s // dif)
    ans = n
    ans -= abs(floorsum(n+1,d,1,0) - floorsum(n+1,s,m,0))
    print(ans,flush=False)
0