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. PHP学习笔记十八【构造函数】

    <?php class Person{ public $name; public $age; //定义构造函数 function 空格__construct 构造方法没有返回值,对象自动调用 p ...

  2. css架构目标:预测,重用,扩展,维护

    请参看下面链接: CSS架构目标:预测.重用.扩展.维护

  3. oracle日记

    win7旗舰版安装oracle11g 64位用sql plus可以登录 但用pl/sql dev报错ORA-12560 小型数据库:access.foxbase 中型数据库:mysql.sqlserv ...

  4. php 大流量网站访问

    1:确认服务器硬件能否支持当前流量 2:数据库优化,用到什么字段查什么字段,减轻查询负担. 3:静态化,缓存,减少连库操作. 4:禁止外部盗链,减轻负载压力. 5:控制文件下载大小,尽量不超过2M,有 ...

  5. setInterval()-----------js 函数总结

    setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 s ...

  6. HTML5 JavaScript 文件上传

    function fileUpload(targetUrl) { // 隐藏表单名称 var inputName = '_fileselect'; // 文件尺寸 this.fileSize = 0; ...

  7. python运维开发(二十四)----crm权限管理系统

    内容目录: 数据库设计 easyUI的使用 数据库设计 权限表Perssion 角色表Role 权限和角色关系表RoleToPermission 用户表UserInfo 用户和角色关系表UserInf ...

  8. JavaScript插件 Bootstrap自带了13个jQuery插件,这些插件为Bootstrap中的组件赋予了“生命”

    原文:http://v2.bootcss.com/javascript.html#popovers

  9. js阻止元素的默认事件与冒泡事件

    嵌套的div元素,如果父级和子元素都绑定了一些事件,那么在点击最内层子元素时可能会触发父级元素的事件,从而带来一定的影响. 1. event.preventDefault();  -- 阻止元素的默认 ...

  10. javacc

    http://www.cnblogs.com/Gavin_Liu/archive/2009/03/07/1405029.html https://javacc.java.net/ http://www ...