[数学][组合数取模] POJ2992

https://cn.vjudge.net/problem/POJ-2992

这个题数据非常严格,极容易TLE。。。需要预处理出阶乘对应的质数的幂次然后查询。对于阶乘中某个质数的指数有结论


然后枚举质数,把分子分母加加减减就行了

 

#include
#include
#include

using namespace std;
const int N=505;
typedef long long LL;



LL prime[100]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,1000000};

LL cal[500][500];

void getcal()
{
    LL t,res;
    for (int i=1;i<=431;i++)
    {
        for (int j=0;prime[j]<=431;j++)
        {
            res=0;
            t=i;
            while(t)
            {
                t/=prime[j];
                res+=t;
            }
            cal[i][prime[j]]=res;
        }
    }
}

int main()
{
    getcal();
    int a,b;
    LL res;
    while(~scanf("%d%d",&a,&b))
    {
        res=1;
        for (int j=0;prime[j]<=a;j++)
        {
            res*=(cal[a][prime[j]]-cal[b][prime[j]]-cal[a-b][prime[j]]+1);
        }
        printf("%lld\n",res);
    }
    return 0;
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据