zoukankan      html  css  js  c++  java
  • hdu 3123 2009 Asia Wuhan Regional Contest Online

    以为有啥牛逼定理,没推出来,随便写写就A了----题非常水,可是wa了一次


    n>=m  则n!==0

    注意的一点,最后 看我的凝视

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    const int  maxn = 115;
    #define ll long long
    
    int main()
    {
        int ncase,len;
        ll m,n,ans,rec;
    
        char num[maxn];
        scanf("%d",&ncase);
        while(ncase--)
        {
            ans=rec=1;
            scanf("%s",num);
            len=strlen(num);
            scanf("%I64d",&m);
            if(len > 7)n=m-1;
            else
            {
                n=0;
                for(int i=0;i<len;i++)n=n*10+num[i]-'0';
            }
            for(int i=1;i<=n;i++)//at end +1%m
            {
                rec=rec*i%m;
                ans=(ans+rec)%m;
            }
    
            printf("%I64d
    ",ans%m);/*注意n==0时 未进入循环,測试数据 0 1 应该是0假设不加%m是1*/
        }
    
        return 0;
    }
    


     

查看全文
  • 相关阅读:
    poj2181 jumping cow
    poj2184
    POJ 1189 钉子和小球
    uva11019矩阵匹配器D316
    noip2015运输计划
    [LintCode] Last Position of Target
    [LintCode] K Closest Points
    [LintCode] K Closest Numbers In Sorted Array
    [LintCode] Closest Number in Sorted Array
    [LintCode] Perfect Squares
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10853395.html
  • Copyright © 2011-2022 走看看