【51NOD-0】1008 N的阶乘 mod P

【算法】简单数学

【题解】多项式展开:(a*b)%p=(a%p*b%p)%p

#include<cstdio>
#include<algorithm>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
int n,p;
int main()
{
    scanf("%d%d",&n,&p);
    int ans=1;
    rep(i,1,n)ans=(1ll*ans*i)%p;
    printf("%d",ans);
    return 0;
}
View Code

 

posted @ 2017-05-24 19:24  ONION_CYC  阅读(288)  评论(0编辑  收藏  举报