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\n",ans%m);/*注意n==0时 未进入循环,測试数据 0 1 应该是0假设不加%m是1*/
    }

    return 0;
}


猜你喜欢

转载自www.cnblogs.com/ldxsuanfa/p/10060264.html
今日推荐