1. 程式人生 > >HDU-6363 bookshelf 莫比烏斯反演

HDU-6363 bookshelf 莫比烏斯反演

bookshelf

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<n,k106).

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

題意:把N本書放到K層的書架上,每一層的美麗值為bi=2fib[cnt]1,其中cnt是這一層書的數量,fib[x]為斐波那契數列,整個書架的美麗值為gcd(b1,b2,...,bk),問整個書架的美麗值的期望

題解:考試的時候因為本人實在是太菜了。對這個題目完全沒有一點思路,考完試以後聽了dls直播算是對這個題目有了一點思路程式碼很短,但是從學習各種姿勢到寫完用了一天,感覺一下子掌握了好多神奇的姿勢,開心。

經典定理:

gcd(xa1,xb1)=xgcd(a,b)1 gcd(fib[a],fib[b])=fib[gcd(a,b)]
那麼對於這個書架的美麗值可以做如下變形:
gcd(b1,b2,...,bk)=gcd(2fib[x1],2fib[x2],...,2fib[xk])=2gcd(fib[x1],2fib[x2],...,2fib[xk])=2fib[gcd(x1,x2,,x1k)]
於是我們設