hdoj-3123-GCC
来源:互联网 发布:linux 监控系统性能 编辑:程序博客网 时间:2024/05/29 08:16
Description
The GNU Compiler Collection (usually shortened to GCC) is a compiler system produced by the GNU Project supporting various programming languages. But it doesn’t contains the math operator “!”.
In mathematics the symbol represents the factorial operation. The expression n! means “the product of the integers from 1 to n”. For example, 4! (read four factorial) is 4 × 3 × 2 × 1 = 24. (0! is defined as 1, which is a neutral element in multiplication, not multiplied by anything.)
We want you to help us with this formation: (0! + 1! + 2! + 3! + 4! + … + n!)%m
Input
The first line consists of an integer T, indicating the number of test cases.
Each test on a single consists of two integer n and m.
Output
Output the answer of (0! + 1! + 2! + 3! + 4! + … + n!)%m.
Constrains
0 < T <= 20
0 <= n < 10^100 (without leading zero)
0 < m < 1000000
Sample Input
1
10 861017
Sample Output
593846
当输入的数字长度大于7时,可以是可以除尽m的
然后分开讨论,边乘边mod就好了
#include<cstring> #include<cstdio> #include<algorithm> #include<iostream> using namespace std; typedef long long ll; int main() { int t; scanf("%d",&t); while(t--) { char s[1000]; int m; ll sum; scanf("%s%d",s,&m); int l=strlen(s); if(l>=7) { sum=m; } else { sum=0; for(int i=0;i<l;i++) { sum*=10; sum+=s[i]-'0'; } } //printf("%I64d\n",sum); ll ans1=1,ans2=1; for(ll i=1;i<=sum;i++) { ans1=(ans1*i)%m; ans2=(ans1+ans2)%m; } ans2%=m; printf("%I64d\n",ans2); } return 0; }
- HDOJ 3123 GCC
- HDOJ 3123 GCC (数学)
- hdoj-3123-GCC
- hdoj GCC 3123 (大数阶乘取余&转换)
- hdoj--3123--GCC(技巧阶乘取余)
- hdu 3123 GCC
- hdu 3123 GCC
- hdu 3123 GCC
- HDU 3123 GCC
- HDU 3123 GCC(数学)
- Hdu 3123 GCC
- HDU 3123 GCC
- HDU 3123 GCC
- HDU-3123-GCC
- HDU 3123 GCC
- HDU 3123 GCC
- HDU-3123 GCC(水题)
- gcc/
- 任意文件包含漏洞
- 认识CoreData-初识CoreData
- JavaScript break跳出多层循环
- 版本库重新定位时svn uuid不一致问题
- CodeForces 289B Polo the Penguin and Matrix
- hdoj-3123-GCC
- HDU5723
- CFS中一些调度参数的实现原理
- 获取时时点击事件 和清除页面内容的方法
- kafka0.9版本指令
- 认识CoreData-基础使用
- Android ViewStub基本使用
- 解决Spring和SpringMVC扫描注解类的冲突问题
- jQuery学习笔记二:选择器