zoukankan      html  css  js  c++  java
  • 51Nod-1008 N的阶乘 mod P【模除】

    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


    问题链接1008 N的阶乘 mod P

    问题分析:计算阶乘模除问题。

    程序说明

    需要注意类型,乘法时结果值有可能比较大,所以要用long long类型。

    把功能封装到函数是好的做法。

    题记:(略)


    参考链接:(略)


    AC的C++程序如下:

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




  • 相关阅读:
    ejs
    appcan.slider.js探索
    js语法重点
    canvas动画
    canvas绘图
    Bootstrap 表单
    模态框
    Node.js EventEmitter(事件队列)
    Node.js 事件循环
    react native 页面跳转
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7563737.html
Copyright © 2011-2022 走看看