結果
| 問題 |
No.2440 Accuracy of Integer Division Approximate Functions
|
| ユーザー |
👑 |
| 提出日時 | 2023-09-06 04:45:03 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 687 bytes |
| コンパイル時間 | 47 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 26,176 KB |
| 最終ジャッジ日時 | 2024-06-23 23:33:05 |
| 合計ジャッジ時間 | 6,836 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | -- * 20 |
コンパイルメッセージ
Syntax OK
ソースコード
# calc sum_{i=0}^{n-1} floor((ai + b) / m)
def floor_sum(n, m, a, b)
x = 0
while n > 0
if a < m && a >= 0
q, a = a.divmod(m)
x += n * (n - 1) / 2 * q
end
if b < m && b >= 0
q, b = b.divmod(m)
x += n * q
end
n, b = (a * n + b).divmod(m)
m, a = a, m
end
x
end
def solve(n, d, m, s)
pow2s, dm = 1 << s, d * m
if pow2s != dm
n = [n, d * pow2s / (pow2s - dm).abs].min
n -= (floor_sum(n + 1, pow2s, m, 0) - floor_sum(n + 1, d, 1, 0)).abs
end
return n
end
for _ in 1..gets.to_i
n, d, m, s = gets.split.map &:to_i
puts solve(n, d, m, s)
end