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的更多相关文章
随机推荐
- C#实现防拷贝工具示例
思路是用加密程序 对硬盘号,cpu号和MAC号取出字符串并加密 产生一个序列号 每次程序启动后重新产生这个序列号并比对,如果一致则验证通过 using System;using System.Coll ...
- iOS 面试题汇总
1. Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么? 答: Object-c的类不可以多重继承;可以实现多个接口,通过实现 ...
- zeromq源码分析笔记之准备(0)
zeromq这个库主要用于进程通信,包括本地进程.网络通信,涉及到一些基础知识,主要包括管道通信,socket编程的内容,反应器模式(使用IO多路复用实现),无锁队列这几块比较重要的部分,下面的几个链 ...
- 内存操作相关内核 API 的使用
1.RtlCopyMemory .RtlCopyBytes.RtlMoveMemory: 2.RtlZeroMemory.RtlFillMemory: 3.RtlEqualMemory: 4.ExAl ...
- JQuery validator扩展
//validator 扩展 jQuery.validator.addMethod("mail", function(value, element, messages) { ret ...
- atom写文档技巧
1. 段落和标题大纲 标题大纲(类似于HTML的H1, H2, …) 简单得很,一级标题用# 标题, 二级标题用## 标题,三级标题用### 标题,以此类推. 段落(类似HTML的<p>) ...
- Flask的session——关于写扩展所学习到的
这两天端午节.趁着端午节没事干,写了个flask的扩展--flask-RedisSession 在flask中使用该扩展可以让你借助redis数据库轻松获得server-side session. 这 ...
- Android中SensorManager.getRotationMatrix函数原理解释
SensorManager是Android中的一个类,其有一个函数getRotationMatrix,可以计算出旋转矩阵,进而通过getOrientation求得设备的方向(航向角.俯仰角.横滚角). ...
- Android 完美实现图片圆角和圆形(对实现进行分析)
本来想在网上找个圆角的例子看一看,不尽人意啊,基本都是官方的Demo的那张原理图,稍后会贴出.于是自己自定义了个View,实现图片的圆角以及圆形效果.效果图: 第一个是原图,第二个是圆形效果,第三第四 ...
- 软件架构 "4+1" 视图模型
1995年,Philippe Kruchten在<IEEE Software>上发表了题为<The 4+1 View Model of Architecture>的论文,引起了 ...