Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
118769 | 6倪葭轩 | 统计硬币 | Python3 | Accepted | 35 MS | 3768 KB | 549 | 2025-05-10 14:11:14 |
import math def count_combinations(n, m): if m < n or m > 5 * n: return 0 delta = m - n # y + 4z = delta # z >= 0, y = delta - 4z >= 0 => z <= delta / 4 # x = n - y - z = n - (delta - 4z) - z = n - delta + 3z >= 0 => 3z >= delta - n => z >= (delta - n)/3 z_min = max(0, math.ceil((delta - n) / 3)) z_max = delta // 4 if z_min > z_max: return 0 return z_max - z_min + 1 T = int(input()) for _ in range(T): n, m = map(int, input().split()) print(count_combinations(n, m))