# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
949037 | rainboy | 개구리들 (YDX13_frogs) | C11 | 9 ms | 3920 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 100000
#define M 10
#define K (N * M)
#define INF 0x3f3f3f3f3f3f3f3fLL
int main() {
static char visited[K];
static int ll[K];
int n, m, c, a, b, r, s, k, l, h;
long long d, lower, upper, x, y;
scanf("%d%d%d%d%lld", &a, &n, &c, &m, &d);
s = 1 * m + 1, k = 0, l = 0;
while (!visited[s]) {
visited[s] = 1;
if (s % m == 0)
l++;
ll[k++] = l;
b = s / m, r = s % m;
b = (long long) b * a % n, r = (r + b) % m;
s = b * m + r;
}
lower = 0, upper = INF;
while (upper - lower > 1) {
x = (lower + upper) / 2;
y = x;
for (h = 0; h + 1 < c; h++)
y = (y / k) * l + ll[y % k];
if (x - y >= d)
upper = x;
else
lower = x;
}
printf("%lld\n", upper);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |