AcWing 1308. 方程的解
原题链接
中等
作者:
清风qwq
,
2022-07-06 20:53:56
,
所有人可见
,
阅读 171
$Code$
// O | O O O
//C_{n - 1}^{k - 1} = k * ... * (n - 1)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5010;
int ans[N], len;
int FastPower(int a, int b)
{
if (b == 1)return a;
int t = FastPower(a, b / 2);
if (b & 1)return (LL)t * t % 1000 * a % 1000;
return (LL)t * t % 1000;
}
void mul(int c)
{
for (int i = 1; i <= len; i ++ )
ans[i] *= c;
for (int i = 1; i <= len; i ++ )
{
ans[i + 1] += ans[i] / 10;
ans[i] %= 10;
}
while (ans[len + 1])
{
len ++ ;
ans[len + 1] = ans[len] / 10;
ans[len] %= 10;
}
}
void div(int c)
{
int r = 0;
for (int i = len; i >= 1; i -- )
{
int d = (ans[i] + r * 10) / c;
r = (ans[i] + r * 10) % c;
ans[i] = d;
}
while (!ans[len])len -- ;
}
void print()
{
for (int i = len; i >= 1; i -- )
cout<<ans[i];
puts("");
}
int main()
{
int n, m;
cin >> n >> m;
m = FastPower(m % 1000, m % 1000);
ans[1] = len = 1;
for (int i = m - n + 1; i < m; i ++ )mul(i);
for (int i = 1; i < n; i ++ )div(i);
print();
return 0;
}