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. FTP 传输中的主动模式和被动模式

    最近做一个项目用到FTP和其它系统进行文件传输,结果在FTP网络连接的问题上花了很多时间,由于太久没搞多FTP,忘记了FTP不单单开放21端口,客户端采用不同连接模式对网络有不同.在此重温一下FTP的 ...

  2. am335x sd卡启动开启识别emmc kernel 上的改动

    sbc 7109-454 sd 卡启动qt系统后一直识别不了  emmc 也就是mmc1口, 一开始以为是硬件初始化的问题,后面又以为是io口复用,最后才知道是根本没有注册mmc1设备. 更改下面的代 ...

  3. 19 BasicTaskScheduler0 基本任务调度类基类(一)——Live555源码阅读(一)任务调度相关类

    这是Live555源码阅读的第二部分,包括了任务调度相关的三个类.任务调度是Live555源码中很重要的部分. 本文由乌合之众 lym瞎编,欢迎转载 http://www.cnblogs.com/ol ...

  4. 【GoLang】golang HTTP GET/POST JSON的服务端、客户端示例,包含序列化、反序列化

    服务端代码示例: package main import ( "encoding/json" "fmt" "io/ioutil" " ...

  5. 【云计算】docker前世今生

    下一代云计算模式:Docker正掀起个性化商业革命 作者: 吴宁川  来源: ITValue  发布时间: 2015-09-20 10:41  阅读: 12976 次  推荐: 24          ...

  6. ASP.NET页面传值不使用QueryString

    ASP.NET页面传值不使用QueryString   Asp.net中的页面传值方法: 1         Url传值 特点:主要优点是实现起来非常简单,然而它的缺点是传递的值是会显示在浏览器的地址 ...

  7. POJ 2769

    http://poj.org/problem?id=2796 题意:求n个数的和乘以这n个数中的最小值的积最大的数,以及其范围. 思路:求每一个数两边的比其大的数的和,再乘以这个数.还有一个范围,用单 ...

  8. Python 开发轻量级爬虫03

    Python 开发轻量级爬虫 (imooc总结03--简单的爬虫架构) 现在来看一下一个简单的爬虫架构. 要实现一个简单的爬虫,有哪些方面需要考虑呢? 首先需要一个爬虫调度端,来启动爬虫.停止爬虫.监 ...

  9. Effective C++ -----条款25:考虑写出一个不抛异常的swap函数

    当std::swap对你的类型效率不高时,提供一个swap成员函数,并确定这个函数不抛出异常. 如果你提供一个member swap,也该提供一个non-member swap用来调用前者.对于cla ...

  10. asp.net mvc htmlHelper

    ASP.NET MVC 3.0 HTML辅助方法   HTML辅助方法(html helper)是用来帮助生成HTML的方法. 1.HTML辅助方法应用实例 ◊ 生成form元素 @using (Ht ...