GCC

Time Limit: 1000MS Memory limit: 65536K

题目描述

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.

输入

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.

0 < T <= 20
0 <= n < 10100 (without leading zero) 
0 < m < 1000000 

输出

Output the answer of (0! + 1! + 2! + 3! + 4! + ... + n!)%m.

示例输入

1
10 861017

示例输出

593846

提示

 

来源

山东理工大学第三届ACM程序设计竞赛
代码:
 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
int zong;
cin>>zong;
while(zong--)
{
char str[];
int mod,num;
cin>>str>>mod;
if(strlen(str)>=)
num=;
else sscanf(str,"%d",&num);
if(num>=mod)
num=mod;
long long int yushu1=,i;
long long int yushu2=;
for(i=;i<=num;i++)
{
yushu1=(yushu1*i)%mod;
if(yushu1==)break;
else
{
yushu2+=yushu1;
yushu2=yushu2%mod;
}
}
cout<<yushu2%mod<<endl;
}
return ;
}

gcc【数学几何】的更多相关文章

  1. hdu 1577 WisKey的眼神 (数学几何)

    WisKey的眼神 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1115 Lifting the Stone (数学几何)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. ACM: FZU 2110 Star - 数学几何 - 水题

     FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Pr ...

  4. poj 1701【数学几何】

    The area Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. LightOj1385 - Kingdom Division(数学几何题)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1385 题意:下图中已知面积 a b c 求 d; 如果d的面积不确定,输出-1. 连接 ...

  6. TZOJ 3244 Happy YuYu's Birthday(数学几何)

    描述 9月10日教师节,也是YuYu的生日,妈妈给YuYu准备了一个很大的圆形蛋糕,YuYu看中了蛋糕中间那诱人的樱桃(都挤到一块啦),小家伙很高兴,心里开始盘算着如何将樱桃全部分给自己.YuYu是个 ...

  7. EOJ Monthly 2018.7 B.锐角三角形(数学几何+思维)

    描述 是否存在面积为S/2的整点锐角三角形?存在输出Yes并输出三个整点坐标,否则输出No. 注意如果存在输出的坐标必须在long long范围内. Input 第一行一个整数S(1<=S< ...

  8. hdu 6097 Mindis(数学几何,圆心的反演点)

    Mindis Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. Tell me the area---hdu1798 (数学 几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=1798 给你两个圆求阴影部分的面积 求出两个扇形的面积减去四边形的面积 扇形的面积是度数(弧度制)*半径的平方 不 ...

随机推荐

  1. java中的jComBox的基本用法

    jComBox获取选中的字符串 getSelectedItem().toString()返回一个字符串 getSelectedItem()返回一个对象. getSelectedIndex()得到选择值 ...

  2. (转)android中颜色矩阵colormatrix

    原文地址:http://www.cnblogs.com/menlsh/archive/2013/02/03/2890888.html 在Android中,对图像进行颜色方面的处理,如黑白老照片.泛黄旧 ...

  3. Tunna内网转发

    Tunna和reduh原理一样.. 使用方法: 上传源码包中文件夹webshell下的脚本至网站目录 然后本地进行连接上传的webshell即可 python proxy.py -u http://1 ...

  4. Dex动态加载

    Dex动态加载是为了解决什么问题? 在Android系统中,一个App的所有代码都在一个Dex文件里面. Dex是一个类似Jar的存储了多个Java编译字节码的归档文件. 因为Android系统使用D ...

  5. ubuntu安装cacti错误

    安装cacti时,明明mysql信息都配置正确了,权限也分配好了,可是仍然报错,如下: 这时可以试试到/etc/cacti目录下,修改debian.php中的mysql配置信息,问题应该就能解决了.

  6. linux文件远程传输客户端shell脚本与分布式客户机时间同步脚本

    #!/bin/bash # 将代码和脚本传送至worker节点 # 改变当前工作目录 cd ${AMAZONCRAWLER_HOME} #读取worker节点ip列表 i= while read li ...

  7. centos 安装gcc时,出错:Found 10 pre-existing rpmdb problem(s), 'yum check' output follows:

    别人折腾的系统. 刚开始,准备安装下tornado,报错,需要安装 gcc 和 python-devel gcc安装报错,如标题所示: 谷歌了一把: http://stackoverflow.com/ ...

  8. angulaijs中的ng-upload-file与阿里云oss服务的结合,实现在浏览器端上传文件到阿里云(速度可以达到1.5M)

    2015-10-26 angularjs结合aliyun浏览器端oos文件上传加临时身份验证例子 在服务端获取sts 源码: public class StsServiceSample { // 目前 ...

  9. gedit配置记

    gedit配置记 起因 突然感觉sublime用用这里那里不方便(虽然很好看> >),然后稍微手调了一下gedit发现gedit还是非常可用的(雾)... 阶段一 我感觉sublime各种 ...

  10. 仿QQ侧滑菜单<大自然的搬运工-代码不是我的>

    1.记录下效果图 2.二个工具类 package myapplication.com.myapplicationfortest.utils; import android.util.Log; /** ...