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)
Total Submission(s): 46 Accepted Submission(s): 14
Alice shows N integers a1, a2, …, aN, and M, K. She says each integers 1 ≤ ai ≤ M.
And now Alice wants to ask for each d = 1 to M, how many different sequences b1, b2, …, bN. which satisfies :
1. For each i = 1…N, 1 ≤ b[i] ≤ M
2. gcd(b1, b2, …, bN) = 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(x1, x2, …, xn) is the greatest common divisor of x1, x2, …, xn
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: a1, a2, ..., an (1 ≤ ai ≤ M) which is original sequence.
The line contains M integer, the i-th integer is the answer shows above when d is the i-th number.
3 3 3
3 5 3
1 2 3
59 3 0 1 1
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
比赛时候想到了做法,但是错估了复杂度,一直没写出来,结束后才搞完、
其实就是从M算到1.
假如现在算i. 那么找到i ~ M中i的倍数。
看原序列中有多少个是i的倍数,设为cnt.
因为最终假如gcd是i的话,所有数都必须是i的倍数。
那就相当于在cnt个中,要把cnt-(N-K)个变掉,其余的(N-cnt)个要变成i的倍数。
i的倍数为t = M/i 个。
那么符合的数有C[cnt][N-K]* (t-1)^(cnt-(N-K)) * t^(N-cnt)
这个算出来的是gcd是i的倍数的情况。
减掉gcd是2i,3i....这样的就行了
/* **********************************************
Author : kuangbin
Created Time: 2013/8/13 16:39:35
File Name : F:\2013ACM练习\2013多校7\1010.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std; const int MOD = 1e9+;
long long pow_m(long long a,long long n)
{
long long ret = ;
long long tmp = a%MOD;
while(n)
{
if(n&)
{
ret *= tmp;
ret %= MOD;
}
tmp *= tmp;
tmp %= MOD;
n >>= ;
}
return ret;
}
long long C[];
//求ax = 1( mod m) 的x值,就是逆元(0<a<m)
long long inv(long long a,long long m)
{
if(a == )return ;
return inv(m%a,m)*(m-m/a)%m;
}
long long ans[];
int a[];
int num[];
int b[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int N,M,K;
while(scanf("%d%d%d",&N,&M,&K) == )
{
memset(num,,sizeof(num));
for(int i = ;i <= N;i++)
{
scanf("%d",&a[i]);
num[a[i]]++;
}
C[N-K] = ;
for(int i = N-K+;i <= N;i++)
{
C[i] = C[i-]*i%MOD*inv(i-(N-K),MOD)%MOD;
}
for(int i = M;i>= ;i--)
{
int cnt = ;
long long ss = ;
for(int j = ; j*i <= M;j++)
{
cnt += num[i*j];
if(j > )ss = (ss + ans[i*j])%MOD;
}
int t = M/i;
if(t == )
{
if(cnt == N-K)ans[i] = ;
else ans[i] = ;
continue;
} if(cnt < N-K)
{
ans[i] = ;
continue;
}
long long tmp = ;
//在cnt个中选N-K个为相同的
tmp =(tmp*C[cnt])%MOD;
//其余的cnt-(N-K)个有t-1个选择
tmp = ( tmp * pow_m(t-,cnt-(N-K)) )%MOD;
//其余N-cnt个本来就不相同的,有t个选择
tmp = (tmp * pow_m(t,N-cnt));
ans[i] = (tmp - ss + MOD)%MOD; }
for(int i = ;i <= M;i++)
{
printf("%I64d",ans[i]);
if(i < M)printf(" ");
else printf("\n");
} }
return ;
}
HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)的更多相关文章
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)
Prince and Princess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- HDU 4691 Front compression (2013多校9 1006题 后缀数组)
Front compression Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4671 Backup Plan (2013多校7 1006题 构造)
Backup Plan Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)
Building Fence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- 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< ...
- 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, -, ...
随机推荐
- caffe Python API 之可视化
一.显示各层 # params显示:layer名,w,b for layer_name, param in net.params.items(): print layer_name + '\t' + ...
- 005_linux下logrotate 配置和理解
对于Linux 的系统安全来说,日志文件是极其重要的工具.系统管理员可以使用logrotate 程序用来管理系统中的最新的事件,对于Linux 的系统安全来说,日志文件是极其重要的工具.系统管理员可以 ...
- 批量生成AWR报告(转载总结)
[前提] 对Oracle进行性能分析其中一个“帮手”就是Oracle的AWR报告 PS:Oracle的企业版才有AWR报告,标准版是没有的{可以导出来,但是没有数据显示} [需求] 当需要针对某个月的 ...
- MySQL 作业题及答案
MySQL 测试题 一. 表关系: 请创建如下表,并创建相关约束 创建表sql如下: /* Navicat MySQL Data Transfer Source Server : 192.168.11 ...
- ie6下png图片背景色处理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- ios测试apk
最近apk在ios上面测试总是会遇到奇奇怪怪的问题,现在是两个项目要集成在一个apk中所以将两个项目运行之后都是编译成了.a文件,然后在两个.a文件中都设置了两个意义相同变量名相同的全局变量(标识当前 ...
- beego学习笔记(4):开发文档阅读(1)
1.beego的设计是高度模块化的.每个模块,都可以单独使用.一共八大模块: cache;session;log;orm;context;httplibs;toolbox 2.beego的执行逻辑 3 ...
- 强大到无与伦比的Graphviz
图1 hello world 尝试画复杂一些的图: 一直苦苦寻找用于图论的画图软件,偶然在Matrix67的这篇博文里找到. Graphviz使用dot语言,这门不仅语言非常简单易学,而且功能却非常强 ...
- Java学习(匿名对象、内部类、包、import、代码块)
一.匿名对象 概念:匿名对象是指在创建对象时,只有创建的语句,却没有把对象地址值赋给某个变量. 特点: (1)匿名对象直接使用,没有变量名.当做形参使用. new Person().name=&quo ...
- WPF 获取计算机字体
//加载计算机上可用的字体 public void LoadFonts(object ietfLanguageTag) { try { var sysFonts = Fonts.SystemFontF ...