# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940858 | rainboy | 팩토리얼 세제곱들의 합 (YDX14_fact) | C11 | 1 ms | 852 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 M 40
#define B 1000000000000
int power(int a, int k) {
return k == 0 ? 1 : power(a, k - 1) * a;
}
int main() {
static long long aa[M], ss[M];
int n, k, h, i, x;
scanf("%d%d", &n, &k);
aa[0] = ss[0] = 1;
for (i = 1; i <= n; i++) {
x = power(i, k);
for (h = 0; h < M; h++)
aa[h] *= x;
for (h = 0; h + 1 < M; h++)
aa[h + 1] += aa[h] / B, aa[h] %= B;
if (aa[M - 1] >= B) {
printf("bad\n");
return 0;
}
for (h = 0; h < M; h++)
ss[h] += aa[h];
for (h = 0; h + 1 < M; h++)
ss[h + 1] += ss[h] / B, ss[h] %= B;
if (ss[M - 1] >= B) {
printf("bad\n");
return 0;
}
}
h = 0;
while (ss[h] == 0)
h++;
while (ss[h] % 10 == 0)
ss[h] /= 10;
printf("%lld\n", ss[h] % 10);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |