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. RDLC添加链接

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdan ...

  2. React react-ui-tree的使用

    公司需要做一个IDE,要做IDE当然少不了文件列表了.下面我就来展示一下刚刚研究的一个库. 下面是链接:https://react.rocks/example/react-ui-tree 至于如何导入 ...

  3. oracle 初探内存结构

    数据库的存储机构 分为 逻辑存储结构 和 物理存储结构 逻辑存储结构: 数据库.表空间.段.区.块         物理存储结构: 数据库.控制文件.数据文件.初始化参数文件.OS块等. 一个区只能在 ...

  4. Webform Lable

  5. Java IO5:管道流、对象流

    前言 前面的文章主要讲了文件字符输入流FileWriter.文件字符输出流FileReader.文件字节输出流FileOutputStream.文件字节输入流FileInputStream,这些都是常 ...

  6. Ubuntu安装samba服务器

    一.安装软件 sudo apt-get install samba 二.配置samba服务器/etc/samba/smb.conf 把默认的配置文件备份,按如下修改配置文件 [global] work ...

  7. linux下virtualenv的python版本

    virtualenv是python开发中一个重要的工具,它可以帮助我们创建一个干净的python解释环境,创建虚拟环境时,这个虚拟环境的 python版本往往是系统默认的2.x版本.别急,我们只需要一 ...

  8. [Zookeeper研究]一 Zookeeper技术简介

    最近的项目中使用到了Zookeeper.Kafka以及Storm.仔细研究了一下,觉得这几个开源项目对于搞分布式的人来说是非常有用的,所以想把自己的一点心得体会总结一下,希望能对大家有所帮助. 首先从 ...

  9. jQuery模拟瀑布流布局

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. linux ar 命令的使用说明那个和例子[转]

    用途说明 创建静态库.a文件.用C/C++开发程序时经常用到,但我很少单独在命令行中使用ar命令,一般写在makefile中,有时也会在shell脚 本中用到.关于Linux下的库文件.静态库.动态库 ...