暴力
就是直接求阶乘然后取模。。。
加一个比较有用的特判:如果n>=p,那么n的阶乘的因子中一定有p,n的阶乘膜p一定等于0
#include <iostream>
#include <cstdio>
using namespace std;
long long n,p;
int js(int n)
{
long long ans=1;
for(int i=2;i<=n;i++)
{
ans=(1ll*ans*i)%p;
}
return ans;
}
int main()
{
scanf("%lld%lld",&n,&p);
if(n>=p)
{
cout<<'0';
return 0;
}
else
{
cout<<js(n)%p;
}
return 0;
}
正解: