hdu3123GCC
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
number of test cases.
Each test on a single consists of two integer n and
m.
n!)%m.
Constrains
0 < T <= 20
0 <= n < 10^100 (without
leading zero)
0 < m < 1000000
10 861017
#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的更多相关文章
随机推荐
- Centos6架设GIT服务,windows客户端使用TortoiseGit加载KEYGEN连接GIT服务器
前几天得空,想起前一阵学了GIT还没好好实践,就在虚拟机中安装测试了一下,并简单记录了CENTOS6中GIT安装,ssh-keygen生成,客户端使用TortoiseGit加载KEYGEN连接GIT服 ...
- ural 1297 Palindrome(Manacher模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 求最长回文子串. http://acm.timus.ru/problem.aspx ...
- HTML5简单入门系列(八)
前言 本篇介绍HTML5中相对复杂的一些APIs,其中的数学知识比较多.虽然如此,但是其实API使用起来还是比较方便的. 这里说明一下,只写出API相关的JS代码,因为他们都是基于一个canvas标签 ...
- Python使用xslt提取网页数据
1,引言 在Python网络爬虫内容提取器一文我们详细讲解了核心部件:可插拔的内容提取器类gsExtractor.本文记录了确定gsExtractor的技术路线过程中所做的编程实验.这是第一部分,实验 ...
- cxf2.7.10 与 spring3.0.5集成
开发环境: NetBeans7.4 Tomcat 6.0.32 一 服务端: 1:新建JavaWeb工程 cxfspring-server,导入jar包如下图所示: 2:在web.xml文件中添加如下 ...
- BZOJ 2875 随机数生成器
http://www.lydsy.com/JudgeOnline/problem.php?id=2875 题意:给出mod,a,c,g,x0,n,xn=(a*xn-1+c)%mod,求xn%g 求A* ...
- SCSI接口图文详解
目前存储设备的接口有五大类:IDE.SCSI.USB,并行口,串口,其中并行口与串口的速度非常慢,不提也罢,最主要的就是IDE,usb,SCSI.IDE(Integrated Drive Electr ...
- 主要协议SCSI、FC、iSCSI
一.SCSI SCSI是小型计算机系统接口(Small Computer System Interface)的简称,于1979首次提出,是为小型机研制的一种接口技术,现在已完全普及到了小型机,高低端服 ...
- TEA加密算法的文件加密和解密的实现
一.TEA加密算法简介 TEA加密算法是由英国剑桥大学计算机实验室提出的一种对称分组加密算法.它采用扩散和混乱方法,对64位的明文数据块,用128位密钥分组进行加密,产生64位的密文数据块,其循环轮数 ...
- PYCURL ERROR 6 - “Couldn't resolve host 'mirrorlist.centos.org'”
在虚拟机上安装的CentOS,估计是网络配置问题,导致yum update和yum install之类的功能的用不了.出现标题上面的错误. ifdown [network_adapter] ifup ...