fzu-2164 Jason's problem(数论)

题意:就是把n的阶乘转化b进制后缀为0的个数为k,求b的个数(n/k < 500)

题解:把n的阶乘分解素因子,枚举前500个素因子即可,找出素因子的个数大于k的

然后就是求符合条件的素因子的组合有多少种;

#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const LL mod = 1000000007;
LL prime[1000];
LL vis[10005];
LL a[1000];
LL b[1000];
LL num;
void init()
{
    num = 0;
    memset(vis,0,sizeof(vis));
    for(LL i = 2; i <= 6000; i++)
    {
        if(!vis[i])
        {
            prime[num++] = i;
            for(LL j = i+i; j <= 6000; j+=i)
            {
                vis[j] = 1;
            }
        }
    }
    
}
int main()
{
    init();
    int T;
    LL n,k,tmp;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%I64d%I64d",&n,&k);
        LL p = 0,i;
        LL ans = 1,ans1 = 1,Sum = 0; ;
        for(i = 0; i < num; i ++)
        {
            tmp = n;
            LL sum = 0;
            while(tmp)
            {
                tmp/=prime[i];
                sum += tmp;
            }
            if(sum >= k)
            {
                LL ss = sum/k+1;
                ans = (ans * ss)%mod;
                a[i] = ss - 1;
                b[i] = sum;
            }
            else break;
        }
        for(LL j = 0; j < i; j++)
        {
            LL count = 0;
            for(LL r = 1; r <= a[j]; r++)
                if(b[j]/r!=k) count++;
            ans1 = (ans1 * (count+1))%mod;
        }
        printf("%I64d\n",((ans-ans1)%mod+mod)%mod);
    }
}
View Code

 

posted @ 2014-04-26 09:43  风儿-zsj  阅读(142)  评论(0编辑  收藏  举报