Submission #18805259
Source Code Expand
Copy
#include <cstdio>long long floor_sum(long long n, long long m, long long a, long long b) {long long ans = 0;if (a >= m) {ans += (n - 1) * n * (a / m) / 2;a %= m;}if (b >= m) {ans += n * (b / m);b %= m;}long long y_max = a * n + b;if (y_max < m) return ans;long long y_max_div = y_max / m;long long y_max_mod = y_max % m;ans += floor_sum(y_max_div, a, m, y_max_mod);return ans;}
#include <cstdio> long long floor_sum(long long n, long long m, long long a, long long b) { long long ans = 0; if (a >= m) { ans += (n - 1) * n * (a / m) / 2; a %= m; } if (b >= m) { ans += n * (b / m); b %= m; } long long y_max = a * n + b; if (y_max < m) return ans; long long y_max_div = y_max / m; long long y_max_mod = y_max % m; ans += floor_sum(y_max_div, a, m, y_max_mod); return ans; } int main() { int t; scanf("%d", &t); for (int i = 0; i < t; ++i) { long long n, m, a, b; scanf("%lld %lld %lld %lld", &n, &m, &a, &b); printf("%lld\n", floor_sum(n, m, a, b)); } }
Submission Info
Submission Time | |
---|---|
Task | C - Floor Sum |
User | rsk0315 |
Language | C++ (GCC 9.2.1) |
Score | 100 |
Code Size | 708 Byte |
Status | AC |
Exec Time | 75 ms |
Memory | 1668 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] 25 | scanf("%d", &t); | ~~~~~^~~~~~~~~~ ./Main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] 29 | scanf("%lld %lld %lld %lld", &n, &m, &a, &b); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 | 6 ms | 1644 KB |
random_00 | AC | 26 ms | 1652 KB |
random_01 | AC | 75 ms | 1644 KB |
random_02 | AC | 61 ms | 1632 KB |
random_03 | AC | 43 ms | 1620 KB |
random_04 | AC | 28 ms | 1668 KB |
small_00 | AC | 18 ms | 1664 KB |
small_01 | AC | 44 ms | 1644 KB |
small_02 | AC | 39 ms | 1644 KB |
small_03 | AC | 31 ms | 1640 KB |
small_04 | AC | 15 ms | 1660 KB |