HDU GCC(HDU 3123)解题报告
来源:互联网 发布:徕卡全站仪传输软件 编辑:程序博客网 时间:2024/05/11 20:07
/*Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2646 Accepted Submission(s): 810
Problem 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
*/
#include<stdio.h>#include<stdlib.h>#include<string.h>char n[1010];__int64 m;int main(){ __int64 num,sum=0; int i,T,m,k; scanf("%d",&T); while(T--) { scanf("%s%d",n,&m); if(strlen(n)>=7) k=m; else k=atoi(n); num=1,sum=1; for(i=1;i<=k;i++) { num=(num*i)%m; sum=(sum+num)%m; } printf("%I64d\n",sum%m); } return 0;}
点击打开链接
- HDU GCC(HDU 3123)解题报告
- HDU 3342 解题报告
- HDU 3336 解题报告
- HDU 3335 解题报告
- hdu 2516解题报告
- hdu 1004解题报告
- hdu 2139解题报告
- hdu 1019解题报告
- hdu 1064 解题报告
- HDU 1113 解题报告
- hdu 1068 解题报告
- HDU:2050解题报告
- hdu 4001解题报告
- hdu 1005解题报告
- HDU解题报告--1003
- HDU解题报告--1004
- HDU解题报告--1005
- HDU 1005 解题报告
- IE浏览器下ajax重复提交的问题处理
- C# 在一个字符串中,找出出现次数最多的字母,并计算次数?
- Fedora install tomcat6
- javascript学习-2
- MSSQL数据库孤立用户解决过程一则
- HDU GCC(HDU 3123)解题报告
- 今天我进来了CSDN论坛了,开始了我的IT生活
- Asterisk behind NAT
- linux shell中kill 和kill all 分析
- Qt远程连接SQlServer数据库
- javascript学习-3
- 了解多态
- ARM处理器的指令系统一 ARM处理器寻址方式
- 存储过程样例--获取数据