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
 
Source

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath> using namespace std; char s[]; int main()
{
long long t,n,md,a,i,sum,l;
cin>>t;
while(t--)
{
cin>>s>>md;
l = strlen(s);
n = ;
if(l>)n = md;
else
for(i = ;i<l;i++)
n = n*+s[i]-'';
sum = a = ;
for(i = ;i<=n;i++)
{
a = (a*i)%md;
sum = (sum+a)%md;
}
sum%=md;
cout<<sum<<endl;
}
return ;
}

hdu3123GCC的更多相关文章

随机推荐

  1. C#winform修改IP,dns

     /// 将IP,DNS设置为自动获取        ///        private void setDHCP()        {            string  _doscmd = & ...

  2. contentSize、contentInset和contentOffset

    contentSize.contentInset和contentOffset 是 scrollView三个基本的属性. contentSize: The size of the content vie ...

  3. javascript sort排序

    var arr = [5,32,28,66,2,15,3]; arr.sort(function(a1,a2){ return a1-a2; //a2-a1 输入倒序 }); console.log( ...

  4. 使用Win32 API 查找文件

    头文件:#include <windows.h> //FindFirstFile() 获得指定目录的第一个文件 HANDLE FindFirstFile( LPCTSTR lpFileNa ...

  5. OpenCV——使用ROI进行图像切割

    ROI(region of interest)——感兴趣区域. 1.用途 这个区域是图像分析所关注的重点.圈定这个区域,以便进行进一步的处理.而且,使用ROI指定 想读入的目标,可以减少处理时间,增加 ...

  6. HDU 1084 - ACM

    题目不难,但是需要对数据进行处理,我的代码有些冗长,希望以后能改进... 主要思路是先算总的时间,然后进行对比,将做同样题数的前一半的人筛选出来. /状态:AC/ Description “Point ...

  7. (原)使用mkl计算特征值和特征向量

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5585271.html 参考文档:mkl官方文档 lapack_int LAPACKE_sgeev(in ...

  8. (原+转)使用opencv的DFT计算卷积

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5462665.html 参考网址: http://blog.csdn.net/lichengyu/art ...

  9. [Leetcode] Find the minimum in rotated sorted array

    我在Github上新建了一个解答Leetcode问题的Project, 大家可以参考, 目前是Java 为主,里面有leetcode上的题目,解答,还有一些基本的单元测试,方便大家起步. 题目: Su ...

  10. Python之路第十二天,高级(6)-paramiko

    paramiko 一.安装 pip3 install paramiko 二.使用 SSHClient 用于连接远程服务器并执行基本命令 1. 基于用户和密码链接 import paramiko # 创 ...