解题思路:
貌似有公式,硬算就是这样,之前没改检测的时候能ac,现在改了,只能过9/100,-.-;
注意事项:
真的离谱,求大佬优化一下(把每个数组内表示一个 改成100 应该可以ac,但是懒得改了)
参考代码:
#include <bits/stdc++.h>
using namespace std;
struct node
{
int number[10000] = {0};
int len = 0;
};
node bigintdivide(int a[], int b[], int a_len, int b_len)
{
int d[a_len - b_len] = {0};
int d_len = a_len - b_len + 1;
int p = a_len - b_len;
while (1)
{
if (p < 0)
{
break;
}
int k = 0;
while (1)
{
// A_reduce_B()
int c[a_len];
for (int i = 0; i < p; i++)
{
c[i] = a[i];
}
for (int i = p; i < b_len + p; i++)
{
c[i] = a[i] - b[i - p];
}
int kk = 0;
while (1)
{
kk = 0;
for (int i = p; i < a_len - 1; i++)
{
if (c[i] < 0)
{
c[i] = c[i] + 10;
c[i + 1] = c[i + 1] - 1;
kk++;
}
}
if (kk == 0)
{
break;
}
}
int pp = c[a_len - 1];
if (pp < 0)
{
memset(c, 0, sizeof(c));
break;
}
else
{
k++;
for (int i = p; i < a_len; i++)
{
a[i] = c[i];
}
if (a[a_len - 1] == 0)
{
memset(c, 0, sizeof(c));
break;
}
}
}
if (a[a_len - 1] > 0)
{
a[a_len - 2] += a[a_len - 1] * 10;
}
a_len--;
d[p] = k;
p--;
}
node nn;
nn.len = d_len;
int pp = 0;
for (int i = d_len - 1; i >= 0; i--)
{
if (pp == 0 && d[i] == 0)
{
nn.len--;
}
else
{
pp = 1;
nn.number[i] = d[i];
}
}
return nn;
}
node bigfactorial(int n, int m)
{
int pp = 0;
int a[10000] = {0};
a[0] = 1;
int a_len = 1;
int b[10000] = {0};
b[0] = 1;
int b_len = 1;
for (int i = n;; i--)
{
for (int j = 0; j < a_len; j++)
{
a[j] *= i;
}
for (int j = 0; j < a_len; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
long long int p = a[a_len - 1];
while (p)
{
a[a_len - 1] = p % 10;
if (p / 10 > 0)
a_len++;
p /= 10;
}
pp++;
if (pp == m)
{
break;
}
}
for (int i = 1; i <= m; i++)
{
for (int j = 0; j < b_len; j++)
{
b[j] *= i;
}
for (int j = 0; j < b_len; j++)
{
b[j + 1] += b[j] / 10;
b[j] %= 10;
}
long long int p = b[b_len - 1];
while (p)
{
b[b_len - 1] = p % 10;
if (p / 10 > 0)
b_len++;
p /= 10;
}
}
return bigintdivide(a, b, a_len, b_len);
}
node bigride(node x, int y)
{
int a_len = x.len;
int a[10000];
for (int i = a_len - 1; i >= 0; i--)
{
a[i] = x.number[i];
}
for (int j = 0; j < a_len; j++)
{
a[j] = a[j] * y;
}
for (int j = 0; j < a_len - 1; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
for (int j = 0; j < a_len - 1; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
long long int p = a[a_len - 1];
while (p)
{
a[a_len - 1] = p % 10;
if (p / 10 > 0)
a_len++;
p = p / 10;
}
node z;
z.len = a_len;
int k = 0;
for (int i = a_len - 1; i >= 0; i--)
{
if (k == 0 && a[i] == 0)
{
z.len--;
}
else
{
k = 1;
z.number[i] = a[i];
}
}
return z;
}
node bigadd(node x, node y)
{
int a_len = max(x.len, y.len);
int a[10000] = {0};
for (int j = 0; j < a_len; j++)
{
if (x.len < j)
{
a[j] = y.number[j];
}
else if (y.len < j)
{
a[j] = x.number[j];
}
else
{
a[j] = x.number[j] + y.number[j];
}
}
for (int j = 0; j < a_len - 1; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
long long int p = a[a_len - 1];
while (p)
{
a[a_len - 1] = p % 10;
if (p / 10 > 0)
a_len++;
p = p / 10;
}
node z;
z.len = a_len;
int k = 0;
for (int i = a_len - 1; i >= 0; i--)
{
if (k == 0 && a[i] == 0)
{
z.len--;
}
else
{
k = 1;
z.number[i] = a[i];
}
}
return z;
}
node nnbigride(node x, node y)
{
int a_len = x.len * y.len;
int a[10000];
for (int i = a_len - 1; i >= 0; i--)
{
a[i] = 0;
}
for (int i = 0; i < x.len; i++)
{
for (int j = 0; j < y.len; j++)
{
a[i + j] += (x.number[i] * y.number[j]);
}
}
for (int j = 0; j < a_len - 1; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
long long int p = a[a_len - 1];
while (p)
{
a[a_len - 1] = p % 10;
if (p / 10 > 0)
a_len++;
p = p / 10;
}
node z;
z.len = a_len;
int k = 0;
for (int i = a_len - 1; i >= 0; i--)
{
if (k == 0 && a[i] == 0)
{
z.len--;
}
else
{
k = 1;
z.number[i] = a[i];
}
}
return z;
}
int main()
{
int n, m, k;
cin >> n >> m >> k;
node a = bigfactorial(n, m);
// cout << a << endl;
node b;
b.number[0] = 0;
b.len = 1;
for (int i = 1; i <= k; i++)
{
node ai = bigfactorial(n, i);
node tt = bigride(ai, pow(i, k));
b = bigadd(b, tt);
}
node c = nnbigride(a, b);
for (int i = c.len - 1; i >= 0; i--)
{
cout << c.number[i];
}
return 0;
}
0.0分
0 人评分