C - N的阶乘 mod P

C - N的阶乘 mod P 
输入N和P(P为质数),求N! Mod P = ? (Mod 就是求模 %)
例如:n = 10, P = 11,10! = 3628800
3628800 % 11 = 10
Input
两个数N,P,中间用空格隔开。(N < 10000, P < 10^9)
Output
输出N! mod P的结果。
Sample Input
10 11
Sample Output
10

#include<iostream>
using namespace std;
typedef long long ll;
int main(){
	ll n,m;
	cin>>n>>m;
	ll ans=1;
	for(ll i=1;i<=n;i++){
		ans=(ans*(i%m))%m;//ans%m*i%m
	}
	cout<<ans<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41333844/article/details/81986364
今日推荐