提交记录 17251
提交时间 |
评测时间 |
2022-01-04 23:10:45 |
2022-01-04 23:10:46 |
#include <stdio.h>
#include <string.h>
typedef unsigned long long ll;
#define MOD 100000000
struct HP{
ll num[10000];
int len;
};
void mul(struct HP x, struct HP y, struct HP *dst) {
dst->len = x.len + y.len - 1;
for (int i = 0; i < dst->len; ++i) {
dst->num[i] = 0;
}
for (int i = 0; i < x.len; ++i) {
for (int j = 0; j < y.len; ++j) {
dst->num[i + j] += x.num[i] * y.num[j];
}
}
for (int i = 0; i < dst->len - 1; ++i) {
if (dst->num[i] > MOD) {
dst->num[i + 1] += dst->num[i] / MOD;
dst->num[i] = dst->num[i] % MOD;
}
}
}
int main() {
struct HP a, b, c;
char buf[10024];
scanf("%s", buf);
int pos = -1;
ll count = 1;
for (int i = strlen(buf) - 1; i >= 0; --i) {
if (count == 1) {
pos++;
a.num[pos] = (int)buf[i] - 48;
count *= 10;
}
else {
a.num[pos] += ((int)buf[i] - 48) * count;
count *= 10;
if (count == MOD) count = 1;
}
}
a.len = pos + 1;
scanf("%s", buf);
pos = -1;
count = 1;
for (int i = strlen(buf) - 1; i >= 0; --i) {
if (count == 1) {
pos++;
b.num[pos] = (int)buf[i] - 48;
count *= 10;
}
else {
b.num[pos] += ((int)buf[i] - 48) * count;
count *= 10;
if (count == MOD) count = 1;
}
}
#ifdef DEBUG
printf("a.len = %d\n", a.len);
printf("a = %d", a.num[a.len - 1]);
for (int i = a.len - 2; i >= 0; --i) {
printf("%08d", a.num[i]);
}
printf("\n");
#endif
b.len = pos + 1;
mul(a, b, &c);
printf("%lld", c.num[c.len - 1]);
for (int i = c.len - 2; i >= 0; --i) {
printf("%08ld", c.num[i]);
}
printf("\n");
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.28 ms | 432 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:32:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠