先放知识点:
莫比乌斯反演
卢卡斯定理求组合数
乘法逆元
快速幂取模

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 n 

Input

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
4

Sample Output

7 1 0
59 3 0 1 1
1
2

Hint

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级别的所以没问题

#include <bits/stdc++.h>
using namespace std;
const int maxn = 310000;
const int mod = 1000000007;
int n, m, k;
int prime[maxn], tot, mu[maxn]; //莫比乌斯函数
bool vis[maxn];
long long fac[maxn], rev[maxn]; //乘法逆元,和卢卡斯定理
long long F[maxn], f[maxn];     //莫比乌斯反演
int a[maxn];
int cnt[maxn]; //对于d,有多少a[i]是d的倍数
long long extend_gcd(long long a, long long b, long long &x, long long &y)
{//扩展欧几里得if (a == 0 && b == 0)return -1;if (b == 0){x = 1;y = 0;return a;}long long d = extend_gcd(b, a % b, y, x);y -= a / b * x;return d;
}
long long mod_rev(long long a, long long n) //乘法逆元lucas用
{long long x, y;long long d = extend_gcd(a, n, x, y);if (d == 1)return (x % n + n) % n;elsereturn -1;
}void init() //线性筛求莫比乌斯函数
{tot = 0;mu[1] = 1;for (int i = 2; i < maxn; i++){if (!vis[i]){prime[tot++] = i;mu[i] = -1;}for (int j = 0; j < tot; j++){if (i * prime[j] >= maxn)break;vis[i * prime[j]] = 1;if (i % prime[j] == 0){mu[i * prime[j]] = 0;break;}else{mu[i * prime[j]] = -mu[i];}}}fac[0] = rev[0] = 1;for (int i = 1; i < maxn; i++){fac[i] = fac[i - 1] * i % mod;//预处理卢卡斯定理参数rev[i] = mod_rev(fac[i], mod);//预处理逆元}
}long long quick_mod(long long a, long long b)
{long long ans = 1;a %= mod;while (b){if (b & 1){ans = ans * a % mod;b--;}b >>= 1;a = a * a % mod;}return ans;
}long long Lucas(long long m, long long n)
{if (n == 0)return 1;long long ans = fac[m] * rev[n] % mod * rev[m - n] % mod;return ans;
}int main()
{init();while (scanf("%d%d%d", &n, &m, &k) != EOF){memset(cnt, 0, sizeof cnt);memset(f, 0, sizeof f);for (int i = 1; i <= n; i++){scanf("%d", &a[i]);cnt[a[i]]++;}for (int i = 1; i <= m; i++)for (int j = i + i; j <= m; j += i)cnt[i] += cnt[j];for (int i = 1; i <= m; i++){long long p = cnt[i];if (k - n + p < 0){F[i] = 0;continue;}F[i] = Lucas(p, k - n + p) * quick_mod(m / i - 1, k - n + p) % mod * quick_mod(m / i, n - p) % mod;}for (int i = 1; i <= m; i++){if (F[i] == 0)f[i] = 0;elsefor (int j = i; j <= m; j += i){f[i] += mu[j / i] * F[j];f[i] %= mod;}printf("%lld", (f[i] + mod) % mod);if (i != m)printf(" ");}printf("\n");}return 0;
}

数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)相关推荐

  1. java乘法逆元与除法取模,关于数论乘法逆元及相关知识点

    在求解a/b%m时,可以转化为(a%(b*m))/b,转化过程如下 令k = (a/b)/m(向下取整), x = (a/b)%m; a/b = k*m + x (x < m); a = k*b ...

  2. gcd + 扩展欧几里得定理+递推乘法逆元(模板)

    gcd: int gcd(int a, int b){ return b==0? a: gcd(b, a%b); } 扩张欧几里得定理: 扩展欧几里德算法是用来在已知a, b求解一组x,y使得ax+b ...

  3. 2019河北省大学生程序设计竞赛(重现赛)B 题 -Icebound and Sequence ( 等比数列求和的快速幂取模)...

    题目链接:https://ac.nowcoder.com/acm/contest/903/B 题意: 给你 q,n,p,求 q1+q2+...+qn 的和 模 p. 思路:一开始不会做,后面查了下发现 ...

  4. 快速幂取模——Pupu(HDU 3003)

    题目: 由题目推出计算公式: ans = (2^(n-1) + 1) % n 因为n取值很大,所以需要用到快速幂取模: int multi(int a,int b) { int ret; ret=1; ...

  5. HDU 4365 正方形格子涂色中心对称轴对称的涂法有多少种-思维-(矩阵坐标关系快速幂取模)

    题意:n*n的格子,涂色,有k种颜料,必须满足旋转任意个90度和翻转之后图片的样子不变,现在已经有m个格子涂过色了,问还有多少种涂法满足上述条件. 分析: 满足上述对称条件,那么涂色的种类问题我们可以 ...

  6. 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂

    Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...

  7. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

  8. 【Project Euler】530 GCD of Divisors 莫比乌斯反演

    [题目]GCD of Divisors [题意]给定f(n)=Σd|n gcd(d,n/d)的前缀和F(n),n=10^15. [算法]莫比乌斯反演 [题解]参考:任之洲数论函数.pdf 这个范围显然 ...

  9. CCPC-Wannafly Winter Camp Day3 (Div2, onsite) F 小清新数论 欧拉函数的利用 莫比乌斯反演 杜教筛

    F - 小清新数论 做法一:欧拉函数 #include<stdio.h> #include<bits/stdc++.h> using namespace std; #defin ...

最新文章

  1. 将模式对话框的返回值回送(PostBack)到服务端
  2. 信息增益有负值吗_一个自动化设备的信息化改造项目,谈谈自动化工程师转型之路—IT融合OT...
  3. 怎么在苹果Mac虚拟机上安装Win7
  4. 整合Druid---SpringBoot
  5. python里什么叫子图_Python中的两个子图(matplotlib)
  6. python爬取b站评论_学习笔记(1):写了个python爬取B站视频评论的程序
  7. javascript进行遍历
  8. jsp include指令标签
  9. 程序员如何内外兼修?
  10. 74hc138译码器制作火灾报警器
  11. Web | MIME类型
  12. Rocksdb 的compaction_filter和table_properties_collector 用法 及 其底层实现
  13. 微信获取公众号二维码
  14. Skyler2003的资源QwQ
  15. 目标检测 | YOLO系列超全讲解v1,v2,v3
  16. 千里挑一!玻色量子获金鸡湖创业大赛人工智能赛道冠军
  17. 关于AD之PCB各层的简单说明
  18. 关于 Python PyQt5 界面运行时提示无法初始化Qt平台的解决方案
  19. 学习笔记——JAVA执行javascript
  20. 云计算机技术的,云计算机技术简介

热门文章

  1. Android开发之fragment之replace用法
  2. 关于ViewPager使用出现的图片覆盖错误问题
  3. gitbook新版本 build命令导出的html不能跳转?
  4. 定制iOS 7中的导航栏和状态栏
  5. DockerONE 干货 深入理解Docker容器和镜像
  6. 发现一个CentOS第三方源epel的仓库地址(repos.fedorapeople.org)
  7. Mac 安装redis
  8. android R.id.转化为view
  9. 大数据学习路线copy自淘宝
  10. Android多媒体学习三:实现自己的Camera