• 51Nod 1008 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的结果。
    Input示例
    10 11
    Output示例
    10

    同余定理:(a+b)%m=(a%m+b%m)%m    a*b%m=(a%m*b%m)%m 
     1 #include <iostream>
     2 #include <cstring>
     3 #include <string>
     4 #include <algorithm>
     5 #include <stdio.h>
     6 using namespace std;
     7 #define LL long long
     8 int main()
     9 {
    10     LL n,p;
    11     scanf("%lld%lld",&n,&p);
    12     if(n==0){
    13         printf("%lld
    ",1%p);
    14     }
    15     else{
    16         LL sum=1;
    17         for(LL i=1;i<=n;++i){
    18             sum=sum%p*i%p;
    19         }
    20         printf("%lld
    ",sum);
    21     }
    22     return 0;
    23 }
  • 相关阅读:
    DbgPrint格式 输出
    string 类常用函数[转]
    pragma warning[转]
    连接符
    ubuntu ftp server
    关于dex

    Topology中各函数调用顺序
    C# 错误捕捉
    操作word,Excel,PPT
  • 原文地址:https://www.cnblogs.com/wydxry/p/7237272.html
Copyright © 2020-2023  润新知