先放知识点:

莫比乌斯反演

卢卡斯定理求组合数

乘法逆元

快速幂取模

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;
else
return -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; else
for (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. HDU - 4675 GCD of Sequence (莫比乌斯反演+组合数学)

    题意:给出序列[a1..aN],整数M和k,求对1-M中的每个整数d,构建新的序列[b1...bN],使其满足: 1. \(1 \le bi \le M\) 2. \(gcd(b 1, b 2, -, ...

  2. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  3. hdu 1097 A hard puzzle 快速幂取模

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10. /*A ha ...

  4. 杭电 2817 A sequence of numbers【快速幂取模】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...

  5. HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)

    GCD of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  6. 数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)

    Describtion First we define: (1) lcm(a,b), the least common multiple of two integers a and b, is the ...

  7. 【数论】【欧拉函数】【筛法求素数】【乘法逆元】【快速幂取模】bzoj2186 [Sdoi2008]沙拉公主的困惑

    http://www.cnblogs.com/BLADEVIL/p/3490321.html http://www.cnblogs.com/zyfzyf/p/3997986.html 翻了翻题解,这两 ...

  8. HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解

    题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...

  9. HDU 4675 GCD of Sequence(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m).对于d(1< ...

随机推荐

  1. NumPy学习2:基本运算

    数组相减: a = array([20, 30, 40, 50])print ab = arange(4)print bc = a-bprint c 结果: [20 30 40 50][0 1 2 3 ...

  2. docker中的dockerfile

    什么是dockerfile? Dockerfile是一个包含用于组合映像的命令的文本文档.可以使用在命令行中调用任何命令. Docker通过读取Dockerfile中的指令自动生成映像. docker ...

  3. 如何提高你使用windows的逼格(windows用成Linux的赶脚)

    一.准备工作 作为一个整洁而有内涵的人,电脑桌面一定要清洁 二.桌面整洁了,软件怎么打开呢?     方案一 方案二.敲重点   我们可以使用终端指令打开windows安装的任意软件: 打开Windo ...

  4. for循环in遍历

    <script> //对象本身没有length,所以不能用for循环遍历 //要用for...in...循环 var aaa = {"name":"拴住&qu ...

  5. 视频图文教学 - 用最快的速度把 DotNet Core Blazor 程序安装到 树莓派中 并且用网页控制 GPIO 闪灯

    前言 dotnet core 在3.0时代已经发展得很好. 尤其是在跨平台方面更已经是达到了很实用的阶段. 作为 dotnet 程序员, 应该对 Linux 有充分的了解, 也可以在业余时间玩玩硬件, ...

  6. 惊呆了,Servlet Filter和Spring MVC Interceptor的实现居然这么简单

    前言 创建型:单例模式,工厂模式,建造者模式,原型模式 结构型:桥接模式,代理模式,装饰器模式,适配器模式,门面模式,组合模式,享元模式 行为型:观察者模式,模板模式,策略模式,责任链模式,状态模式, ...

  7. C++ 11 +,开坑。

    最近换新工作了.工作中需要用到高端的c++11的一些操作,至于我后面又plus一下还是因为可能是c++14或者17中提供的一些操作.反正都是c++11以及之后的一些特性. 首先,今天看一下关于函数模板 ...

  8. sqli-labs通关教程----41~50关

    第四十关 与前几关一样,闭合变成') 插入数据 ?id=1') ;insert into users(id,username,password) values('17','aaa','bbb'); % ...

  9. asp.net core webapi Session 内存缓存

    Startup.cs文件中的ConfigureServices方法配置: #region Session内存缓存 services.Configure<CookiePolicyOptions&g ...

  10. Linux学习笔记(六)压缩和解压缩命令

    压缩和解压缩命令 zip unzip gzip gunzip bzip2 bunzip2 tar zip (.zip格式的压缩文件) 英文原意:package and compress (archiv ...