51nod 1008 N的阶乘 mod P
2015-10-16 18:40
197 查看
输入N和P(P为质数),求N! Mod P = ? (Mod 就是求模 %)
例如:n = 10, P = 11,10! = 3628800
3628800 % 11 = 10
Input
Output
Input示例
Output示例
变乘边取余,注意用long long来存,防止爆int
例如: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
变乘边取余,注意用long long来存,防止爆int
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; int main() { ll n,mod,ans; ans=1; cin>>n>>mod; if(n>=mod) { cout<<"0"<<endl; return 0; } for(ll i=1;i<=n;i++) { ans=ans%mod*i%mod; } cout<<ans<<endl; return 0; }
相关文章推荐
- 和喜欢的女生聊天 15 分钟以后就找不到话题了怎么办?
- ionic 集成极光推送和增加本地插件
- typecheck(type,x) 作用
- 黑马程序员——Java中的异常处理
- Hive
- 仅需三步,让您的员工绩效都得A!
- 什么是权限管理
- A + B Is Overflow
- 51nod 1073 约瑟夫环 (数学)
- mac换硬盘重装系统记录
- Linux在简短而经常使用的命令
- android解析加载图片的3种方式
- 【日常学习】【强连通分量tarjan缩点】codevs1611 抢掠计划题解
- 分布式协调框架Zookeeper
- 腾讯和58都市“聘请”秘诀是什么?
- unity, inspector debug
- Spring中的p标签
- Buffer Latch Timeout的解析
- GMM模型初探
- 项目中对模板和js,css文件进行压缩的处理类