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 ...
随机推荐
- winform中嵌入Ppt、Word、Excel
1.下载DsoFramer_KB311765_x86.exe 2.安装,默认路径安装C:\DsoFramer. 3.注册:开始菜单——>运行 输入:regsvr32 C:\DsoFramer\d ...
- WCF+EntityFramework+mysql总结
用WCF+Ef操作Mysql数据库的,现在,写一下经验总结,希望对大家有帮助. 1.需下载并安装MySql Connector Net 6.5.4 2.在ef层和wcf服务层引用dll :Mysql. ...
- 数据结构学习笔记05图 (邻接矩阵 邻接表-->BFS DFS、最短路径)
数据结构之图 图(Graph) 包含 一组顶点:通常用V (Vertex) 表示顶点集合 一组边:通常用E (Edge) 表示边的集合 边是顶点对:(v, w) ∈E ,其中v, w ∈ V 有向边& ...
- 小米miui5系统的webview在处理动画事件transitionEnd事件时,竟然要用transitionend才行
一般的安卓系统用的是webkitTransitionEnd, 而小米的系统我用了webkitTransitionEnd事件无法执行,只能用transitionend才会被执行,怪
- RAP开发入门-开发笔记
一.发布/运行 每次项目发布时需要在MANIFEST.MF->bulid中勾选依赖包.文件.代码等,避免报错 部署时项目可能会报一个baseline的错误,window->preferen ...
- Android-----第三方 ImageLoader 的简单配置和使用
ImageLoader 的简单使用配置,最好是将配置信息放到application里面,这样我们就不需要每次使用都需要配置了 1.首先我们得有一个包 2.简单的配置信息 //显示图片的配置 Displ ...
- poj 3580 SuperMemo
题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...
- SQLite之读取数据库内容
1.打开已有数据库. //打开数据库 - (BOOL )openDB {// 红色部分修改为自己的数据库路径 return (SQLITE_OK == sqlite3_open([@"/Us ...
- The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
The ObjectContext instance has been disposed and can no longer be used for operations that require a ...
- R统计图
主题:R统计图 作者:luomg 关键字:统计,R,ggplot2 1.什么是统计图? 统计图:统计图是从数据到几何对象的图形属性的一个映射 砖石重量对价格的散点图 qplot(carat,price ...