51Nod--1008

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
 收藏
 关注
输入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的结果。
Input示例
10 11
Output示例
10
解题思路:模运算的性质
源代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    long long a,b,i,result;
    scanf("%lld%lld",&a,&b);
    result = 1;
    for(i = 1; i <= a; i++)
    {
        result = (result % b * i % b)%b;
    }
    printf("%lld
",result);
    return 0;
}


原文地址:https://www.cnblogs.com/lemonbiscuit/p/7776106.html