zoukankan      html  css  js  c++  java
  • gcc【数学几何】

    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程序设计竞赛
    代码:
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<stdlib.h>
     5 #include<algorithm>
     6 using namespace std;
     7 int main()
     8 {
     9     int zong;
    10     cin>>zong;
    11     while(zong--)
    12     {
    13         char str[10004];
    14         int mod,num;
    15         cin>>str>>mod;
    16         if(strlen(str)>=7)
    17             num=1000000;
    18         else sscanf(str,"%d",&num);
    19         if(num>=mod)
    20             num=mod;
    21         long long int yushu1=1,i;
    22         long long int yushu2=1;
    23         for(i=1;i<=num;i++)
    24         {
    25             yushu1=(yushu1*i)%mod;
    26             if(yushu1==0)break;
    27             else
    28             {
    29                 yushu2+=yushu1;
    30                 yushu2=yushu2%mod;
    31             }
    32         }
    33          cout<<yushu2%mod<<endl;
    34     }
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    GIS的发展
    ajax请求头加Token时发生的跨域(CORS)请求问题
    js 给定时间,如'20130830',换算和今天的天数差
    过程改进点滴需求调研经验之一
    昨天向PAM推荐的好书
    关于专人整理和分析需求
    走出开发混沌
    过程改进点滴需求调研经验之二
    代码重构注意事项
    插件框架内核完成
  • 原文地址:https://www.cnblogs.com/kuangdaoyizhimei/p/3407634.html
Copyright © 2011-2022 走看看