51Nod--1008

来源:互联网 发布:mac安装虚拟机教程 编辑:程序博客网 时间:2024/06/13 00:39
1008 N的阶乘 mod P
基准时间限制: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\n",result);    return 0;}


1 0
原创粉丝点击