hdu 2019多校 Just Skip The Problem

题目传送门:Just Skip The Problem
思路:
n<=1e9。
最优方案,即对每位进行询问,一共n个二进制位。方案数->n!
由于题目中让你总方案数 % 1e6+3.
则可以想到, n>=1e6+3 的时候,全都是0。前面的则先打表预处理就好。
代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
const int mod=1e6+3;
ll a[maxn];
int main()
{
    a[1]=1;
    for(int i=2;i<=1e6+3;i++)
    {
        a[i]=a[i-1]*i%mod;
    }
    ll n;
    while(~scanf("%lld",&n))
    {
        if(n>=1e6+3)printf("0\n");
        else printf("%lld\n",a[n]);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gugudesu/p/11241206.html