B - bookshelf HDU - 6363 莫比乌斯反演

 

bookshelf

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 598    Accepted Submission(s): 273


 

Problem Description

Patrick Star bought a bookshelf, he named it ZYG !!

Patrick Star has N book .

The ZYG has K layers (count from 1 to K ) and there is no limit on the capacity of each layer !

Now Patrick want to put all N books on ZYG :

1. Assume that the i-th layer has cnti(0≤cnti≤N) books finally.

2. Assume that f[i] is the i-th fibonacci number (f[0]=0,f[1]=1,f[2]=1,f[i]=f[i−2]+f[i−1] ).

3. Define the stable value of i-th layers stablei=f[cnti] .

4. Define the beauty value of i-th layers beautyi=2stablei−1 .

5. Define the whole beauty value of ZYG score=gcd(beauty1,beauty2,...,beautyk) (Note: gcd(0,x)=x ).

Patrick Star wants to know the expected value of score if Patrick choose a distribute method randomly !

 

 

Input

The first line contain a integer T (no morn than 10), the following is T test case, for each test case :

Each line contains contains three integer n,k(0

 

 

Output

For each test case, output the answer as a value of a rational number modulo 109+7 .

Formally, it is guaranteed that under given constraints the probability is always a rational number pq (p and q are integer and coprime, q is positive), such that q is not divisible by 109+7 . Output such integer a between 0 and 109+6 that p−aq is divisible by 109+7 .

 

 

Sample Input

 

1 6 8

 

 

Sample Output

 

797202805

 

 

Source

2018 Multi-University Training Contest 6

 

 

贴个板子,过段时间再来写题解。。光是A过就要吐了。。

有一篇不错的分析的文:https://blog.csdn.net/codeswarrior/article/details/81565716


#include
using namespace std;
typedef long long ll;
const int maxn=2000005;
const int mod=(int)1e9+7;
int prime[maxn],numprime,mobi[maxn],vis[maxn];
ll fac[maxn],inv_fac[maxn],n,k,fib[maxn];
ll quick(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
ll C(ll n,ll m){
    if(n<0||m<0||m>n) return 0;
    if(n==m||m==0) return 1;
    return fac[n]*inv_fac[n-m]%mod*inv_fac[m]%mod;
}
void initmob(){//莫比乌斯反演
    mobi[1]=1;
    for(int i=2;i=0;i--)
        inv_fac[i]=inv_fac[i+1]*(i+1)%mod;
}
void initquick(){
    fib[1]=fib[2]=1;
    for(int i=3;i>t;
    while(t--){
        scanf("%lld%lld",&n,&k);
        ll ans=0;
        for(ll i=1;i<=n;i++){
            if(n%i) continue;
            ll tempans=0;
            for(int j=i;j<=n;j+=i)
                if(n%j==0){
                    tempans=(tempans+mobi[j/i]*C(n/j+k-1,k-1)+mod)%mod;
                    }
            ans=(ans+tempans*(quick(2ll,fib[i]+mod-1)+mod-1))%mod;//快速幂降幂
        }
        ll tmp=C(n+k-1,k-1);
        tmp=quick(tmp,(ll)mod-2);
        printf("%lld\n",ans*tmp%mod);
    }
    return 0;
}

 

你可能感兴趣的:(组合数学,模板,数论)