Submit Info #747

Problem Lang User Status Time Memory
Sum of Floor of Linear cpp (anonymous) AC 56 ms 1.80 MiB

ケース詳細
Name Status Time Memory
example_00 AC 1 ms 0.71 MiB
random_00 AC 16 ms 0.96 MiB
random_01 AC 56 ms 1.80 MiB
random_02 AC 42 ms 1.55 MiB
random_03 AC 30 ms 1.25 MiB
random_04 AC 15 ms 0.92 MiB
small_00 AC 9 ms 0.80 MiB
small_01 AC 31 ms 0.98 MiB
small_02 AC 26 ms 0.92 MiB
small_03 AC 18 ms 0.80 MiB
small_04 AC 13 ms 0.73 MiB

#include <bits/stdc++.h> using namespace std; int64_t f(int a, int b, int c, int n) { if (n < 0 || a == 0) return 0; if (a >= c || b >= c) return (a / c) * (1LL * n * (n + 1) / 2) + 1LL * (b / c) * (n + 1) + f(a % c, b % c, c, n); int64_t m = (1LL * a * n + b) / c; return 1LL * n * m - f(c, c - b - 1, a, m - 1); } int main() { int t; scanf("%d", &t); while (t--) { int n, m, a, b; scanf("%d%d%d%d", &n, &m, &a, &b); printf("%lld\n", f(a, b, m, n - 1)); } }