Submission #17871107
Source Code Expand
def floor_sum(n, m, a, b):
ans = 0
if a >= m:
ans += (n - 1) * n * (a // m) // 2
a %= m
if b >= m:
ans += n * (b // m)
b %= m
y_max = (a * n + b) // m
x_max = y_max * m - b
if y_max == 0: return ans
ans += (n - (x_max + a - 1) // a) * y_max
ans += floor_sum(y_max, a, m, (-x_max)% a)
return ans
def main():
t = int(input())
for _ in range(t):
n, m, a, b = map(int, input().split())
print(floor_sum(n, m, a, b))
if __name__ == "__main__":
main()
Submission Info
| Submission Time | |
|---|---|
| Task | C - Floor Sum |
| User | Akari__ |
| Language | Python (3.8.2) |
| Score | 100 |
| Code Size | 573 Byte |
| Status | AC |
| Exec Time | 1162 ms |
| Memory | 9216 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00 |
| All | example_00, random_00, random_01, random_02, random_03, random_04, small_00, small_01, small_02, small_03, small_04 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00 | AC | 20 ms | 8864 KiB |
| random_00 | AC | 318 ms | 9216 KiB |
| random_01 | AC | 1162 ms | 8884 KiB |
| random_02 | AC | 907 ms | 9004 KiB |
| random_03 | AC | 621 ms | 9000 KiB |
| random_04 | AC | 269 ms | 8992 KiB |
| small_00 | AC | 144 ms | 8888 KiB |
| small_01 | AC | 499 ms | 8884 KiB |
| small_02 | AC | 385 ms | 9136 KiB |
| small_03 | AC | 271 ms | 8884 KiB |
| small_04 | AC | 125 ms | 9216 KiB |