hdu 3123
GCC
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3754 Accepted Submission(s):
1216
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
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
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL; void solve(int sum,int p)
{
int i;
LL ans = ,cur = % p ;
for(i=;i<=sum;i++)
{
ans = (ans * i)%p;
cur = (cur + ans)%p;
if(ans == )break;
}
printf("%I64d\n",cur);
}
int main()
{
int T;
int i,p;
char a[];
scanf("%d",&T);
while(T--)
{
scanf("%s%d",a,&p);
if(p==)
{
printf("0\n");
continue;
}
int sum = ;
for(i=;a[i]!='\0';i++)
{
sum=sum*+a[i]-'';
if(sum>=p)break;
}
solve(sum,p);
}
return ;
}
hdu 3123的更多相关文章
- hdu 3123 GCC 阶乘
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3123 The GNU Compiler Collection (usually shortened t ...
- hdu 3123 GCC
这题分2种情况: 1) n>=m时,k!%m=0(k>=m),所以只需令n=m-1即可: 2) n<m时,正常情况处理即可. ;}
- 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 2009 Asia Wuhan Regional Contest Online
以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次 n>=m 则n!==0 注意的一点,最后 看我的凝视 #include <cstdio> #includ ...
- HDU 3091 - Necklace - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
- HDU 1284 钱币兑换问题 母函数、DP
题目链接:HDU 1284 钱币兑换问题 钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- android中的命令安装与卸载
软件的安装: adb install apk的保存地址 卸载软件: adb uninstall package名
- Facebook开源项目:我们为什么要用Fresco框架?
(Facebook开源项目)Fresco:一个新的Android图像处理类库 在Facebook的Android客户端上快速高效的显示图片是非常重要的.然而多年来,我们遇到了很多如何高效存储图片的问题 ...
- 夺命雷公狗jquery---6属性选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- opencv的一次性配置
最近做自然场景中的文字识别,想尝试些图像处理方法,感觉每一种方法都需要自己写很麻烦,自然就想到了强大的开源的跨平台计算机视觉库OpenCv.我用的是opencv2.4.9版本,VS用的是2010,他们 ...
- c++ 容器(list学习总结)
list是一个线性双向链表结构,它的数据由若干个节点构成,每一个节点都包括一个信息块(即实际存储的数据).一个前驱指针和一个后驱指针.它无需分配指定的内存大小且可以任意伸缩,这是因为它存储在非连续的内 ...
- SQL Server安装完成后3个需要立即修改的配置选项(转载)
你用安装向导安装了全新的SQL Server,最后你点击了完成按钮.哇噢~~~现在我们可以把我们的服务器进入生产了!抱歉,那并不是真的,因为你的全新SQL Server默认配置是错误的. 是的,你没看 ...
- intall vs code in elementary os
Open Terminal & Type Install Ubuntu Makesudo apt-get install ubuntu-make Microsoft Visual Studio ...
- Visual studio 中编译错误SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
把写好的sql脚本,并在mssqlmanager里面编译成功的存储过程脚本复制到vs项目下,出现错误信息如下:SQL71006: Only one statement is allowed per b ...
- 锋利的JQuery(三)
事件冒泡: 解决方式: 1.使用事件对象:$("element").bind("click",function(event){}); 这个事件对象只有事件处理函 ...
- plsql 简单介绍
plsql的安装: 1. 安装plsql developer 2. 下载,解压instantclient到任意目录 3. 在instantclient解压目录下,新建NETWORK目录,在该目录下建A ...