hdu 3123 GCC 阶乘
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123
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
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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
typedef long long LL; LL n,m;
char str[]; int main()
{
int t ;scanf("%d",&t) ;
while (t--)
{
scanf("%s%I64d",str,&m);
if (str[]=='') {printf("%I64d\n",(LL)%m);continue; }
LL sum=,len=strlen(str);
for (LL i= len->= ? len- : ;i<=len- ;i++) sum=sum*+str[i]-'';
LL ans=,a=;
for (LL i= ;i<=sum && i<=m ;i++)
{
a=a*i%m;
ans=(ans+a)%m;
}
printf("%I64d\n",ans%m);
}
return ;
}
hdu 3123 GCC 阶乘的更多相关文章
- hdu 3123 GCC (2009 Asia Wuhan Regional Contest Online)
GCC Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- hdu 3123 GCC
这题分2种情况: 1) n>=m时,k!%m=0(k>=m),所以只需令n=m-1即可: 2) n<m时,正常情况处理即可. ;}
- hdu 3123
GCC Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- HDOJ(HDU) 2212 DFS(阶乘相关、)
Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...
- hud 3123 GCC
题目 输入:n 和 mod 输出: Output the answer of (0! + 1! + 2! + 3! + 4! + ... + n!)%m. Constrains 0 < T &l ...
- HDU 1042 大数阶乘
B - 2 Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 3123 2009 Asia Wuhan Regional Contest Online
以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次 n>=m 则n!==0 注意的一点,最后 看我的凝视 #include <cstdio> #includ ...
- HDU 1018Big Number(大数的阶乘的位数,利用公式)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1018 Big Number (阶乘位数)
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...
随机推荐
- Silverlight 使用IsolatedStorage新建XML文件,并且用LINQ查询XML
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- ...
- centos下安装php环境
centos下安装php环境 安装apache yum install httpd-devel 启动apache /etc/init.d/httpd start 安装mysql yum install ...
- Laravel 安装predis 扩展
在安装predis扩展之前先安装composer,安装教程在https://getcomposer.org/download/: php -r "copy('https://getcompo ...
- 【转】利用DCC32实现命令行批量编译
*.dof [Compiler] A=1 B=0 C=1 D=1 E=0 F=0 G=1 H=1 I=1 J=1 K=0 L=1 M=0 N=1 O=1 P=1 Q=0 R=0 S=0 T=0 U=0 ...
- .NET Framework4.0 下的多线程
一.简介 在4.0之前,多线程只能用Thread或者ThreadPool,而4.0下提供了功能强大的Task处理方式,这样免去了程序员自己维护线程池,而且可以申请取消线程等...所以本文主要描述Tas ...
- 关于FragmentManager findFragmentById 返回nul
先看Fragment的两种生成方式 一.用xml标签生成 在fragment的宿主activity中添加xml标签 <fragment android:id="@+id/fragmen ...
- 第十四章 调试及安全性(In .net4.5) 之 对称及非对称加密
1. 概述 本章内容包括:对称及非对称加密算法..net中的加密类.使用哈希操作.创建和管理签名认证.代码访问权限 和 加密字符串. 2. 主要内容 2.1 使用对称和非对称加密 ① 对称加密:使用同 ...
- python 装饰器(decorator)
装饰器(decorator) 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 装饰器(decorator)是一种高级Python语 ...
- rails 学习笔记
bundle package #保存gem到 vendor/cache bundle install –local 从cache从安装 升级rails bundle config –delete ...
- [整理归档]30 common tasks you perform using the GUI that you can do faster in Windows PowerShell
主要内容来自于 http://channel9.msdn.com/Events/TechEd/Australia/2014/DCI316 可以下载PPT以及视频,个人只是整理一下平时常用的 NetWo ...