数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
生活随笔
收集整理的這篇文章主要介紹了
数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先放知識點:
莫比烏斯反演
盧卡斯定理求組合數
乘法逆元
快速冪取模
GCD of Sequence
Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b 1, b 2, …, b N. which satisfies : 1. For each i = 1…N, 1 ≤ b[i] ≤ M 2. gcd(b 1, b 2, …, b N) = d 3. There will be exactly K position i that ai != bi (1 ≤ i ≤ n)Alice thinks that the answer will be too large. In order not to annoy Bob, she only wants to know the answer modulo 1000000007.Bob can not solve the problem. Now he asks you for HELP! Notes: gcd(x 1, x 2, …, x n) is the greatest common divisor of x 1, x 2, …, x nInput
The input contains several test cases, terminated by EOF. The first line of each test contains three integers N, M, K. (1 ≤ N, M ≤ 300000, 1 ≤ K ≤ N) The second line contains N integers: a 1, a 2, …, a n (1 ≤ a i ≤ M) which is original sequence.Output
For each test contains 1 lines : The line contains M integer, the i-th integer is the answer shows above when d is the i-th number.Sample Input
3 3 3 3 3 3 3 5 3 1 2 3 1 2 3 4Sample Output
7 1 0 59 3 0 1 1 1 2Hint
In the first test case : when d = 1, {b} can be : (1, 1, 1) (1, 1, 2) (1, 2, 1) (1, 2, 2) (2, 1, 1) (2, 1, 2) (2, 2, 1) when d = 2, {b} can be : (2, 2, 2) And because {b} must have exactly K number(s) different from {a}, so {b} can't be (3, 3, 3), so Answer = 0
盧卡斯求組合數是log級別的所以沒問題
總結
以上是生活随笔為你收集整理的数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows office365有ac
- 下一篇: 我也不知道该咋分类--莫队算法