hdu3123GCC

时间:2022-03-17 22:40:51
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&num;执行bat批处理文件,并通过线程将结果显示在控件中

      核心代码如下: Process p = new Process(); p.StartInfo.FileName = filePath; p.StartInfo.UseShellExecute = fa ...

    2. 分享一个web存储方法

      https://github.com/zhujiasheng/jquery-cookie/blob/master/src/jquery.cookie.js https://github.com/WQT ...

    3. 团队项目NABCD模型的需求分析

      团队项目NABCD模型的需求分析 NABCD模型的介绍 Need(需求)-现在市场上未被满足但又急需满足的客户需求是什么?Approach(方法)-要满足这种需求,我能够提出什么独特的方法吗?Bene ...

    4. 当前最上层的视图控制器vc 和 当前最上层的导航控制器nav

      在处理 URL Router 跳转的时候,我们经常需要得到 当前最上层的视图控制器 和 当前最上层的导航控制器 来进行视图跳转或者方法调用.- (UIViewController *)currentV ...

    5. Python之参数类型、变量

      一.参数类型 (一)形参与实参 要使用局部变量时,只能通过return的方式返回 def my(name): #函数体 return name my('lrx') #name是形参,lrx是实参 不写 ...

    6. 【原创】Java基础之简单修改jar包中的class

      有时需要修改很多jar(假设这些jar都位于lib目录)中其中一个jar中的某一个类,而且又没有原始代码或ide,这时最简单的方式是: 1 进入lib目录 # cd lib # ls test.jar ...

    7. HashMap理解

      HashMap中Capacity为数组长度,默认大小为16,size为元素个数,loadFactor为size/capacity,默认为0.75,当存储的元素个数size大于等于capacity乘以0 ...

    8. Excel设置excel打印每页都有表头标题

      Excel设置excel打印每页都有表头标题

    9. Vim配色方案报错解决方案

      求Linux大神解答,我刚刚从网上下载了个vim的配色方案,配置好后启动vim就报如下错误,怎么处理呢?小白,求不被鄙视~ 处理 /usr/share/vim/vim72/colors/rainbow ...

    10. DOS下读取PCI配置空间信息的汇编程序(通过IOCF8&sol;IOCFC)

      汇编程序编写的读取PCI配置空间信息的代码(通过IOCF8/IOCFC): ;------------------------------------------------ ;功能: 读取PCI 配 ...

    相关文章