結果
問題 |
No.2440 Accuracy of Integer Division Approximate Functions
|
ユーザー |
👑 |
提出日時 | 2023-09-06 04:47:07 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 752 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-06-23 23:34:56 |
合計ジャッジ時間 | 5,253 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 |
ソースコード
# calc sum_{i=0}^{n-1} floor((ai + b) / m) def floor_sum(n: int, m: int, a: int, b: int) -> int: assert n >= 0 and m > 0 x = 0 while n > 0: if a >= m or a < 0: q, a = divmod(a, m) x += (n * (n - 1) >> 1) * q if b >= m or b < 0: q, b = divmod(b, m) x += n * q n, b = divmod(a * n + b, m) m, a = a, m return x def solve(n: int, d: int, m: int, s: int) -> int: pow2s, dm = 2 ** s, d * m if pow2s != dm: n = min(n, (d * pow2s - 1) // abs(pow2s - dm)) n -= abs(floor_sum(n + 1, pow2s, m, 0) - floor_sum(n + 1, d, 1, 0)) return n for _ in range(int(input())): n, d, m, s = map(int, input().split()) print(solve(n, d, m, s))