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 : Output For each test case, output the answer as a value of a rational number modulo 109+7. Sample Input 1 6 8 Sample Output 797202805 这道题还是蛮好的,把 欧拉降幂+容斥定理(莫比乌斯)+数论知识 题意: 告诉我们有K个桶,一共n个球,把这n个球放到 这k 个桶中,然后定义一个魅力值,让我们求期望。魅力值是 所有层的gcd(), 然后魅力值就是 前置技能:1. 2. 上述两式都可以推广到n个 首先考虑两个桶里面的球,分别为和,对于这两层的魅力值为,也就是 ; 所以推广到k个桶,就是 , 枚举所有的方案是不可能的,所以我们考虑枚举这个 , 的取指最多只有n个,我们是存在枚举的可能的。 直接考虑 ,不好考虑,我们可以考虑 的倍数,然后容斥定理计算一下 然后就是莫比乌斯反演的基本操作了
Each line contains contains three integer n,k(0
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.#include