結果
| 問題 |
No.2440 Accuracy of Integer Division Approximate Functions
|
| ユーザー |
|
| 提出日時 | 2023-08-31 19:23:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 688 bytes |
| コンパイル時間 | 350 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 81,152 KB |
| 最終ジャッジ日時 | 2025-01-03 04:47:40 |
| 合計ジャッジ時間 | 8,107 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 20 |
ソースコード
def floorSum(n, m, a, b):
if n == 0:
return 0
ans = n * (n - 1) * (a // m) // 2 + n * (b // m)
a %= m
b %= m
last = a * (n - 1) + b
last_div = last // m
last_mod = last % m
ans += last_div + floorSum(last_div, a, m, last_mod)
return ans
def solve():
N, D, M, S = map(int, input().split())
if M * D == 2 ** S:
return N
if M * D > 2 ** S:
lim = (M * (D - 1) - 1) // (M * D - 2 ** S)
print(lim > N)
return floorSum(lim, M, 2 ** S - M * D, 2 ** S)
if M * D < 2 ** S:
lim = (2 ** S - 1) // (2 ** S - M * D)
print(lim > N)
return floorSum(lim, M, M * D - 2 ** S, M * (D - 1) - 1)
Q = int(input())
for i in range(Q):
print(solve())