hdu 4675 GCD of Sequence
数学题!
从M到1计算,在计算i的时候,算出原序列是i的倍数的个数cnt;
也就是将cnt个数中的cnt-(n-k)个数变掉,n-cnt个数变为i的倍数。
且i的倍数为t=m/i;
则符合的数为:c[cnt][n-k]*t^(n-cnt)*(t-1)*(cnt-(n-k)).
这样得到的是所有i的倍数,还要减去2*i,3*i……
代码如下:
#include<stdio.h>
#include<cstring>
#define M 1000000007
#define MM 300001
#define ll __int64
#define I(x) scanf("%d",&x)
int a[MM],num[MM];
ll c[MM],an[MM],sum;
ll pows(ll a,ll b)
{
ll ans=;
while(b){
if(b&) ans=(ans*a)%M;
b>>=;
a=(a*a)%M;
}
return ans;
}
ll inv(ll a,ll m)
{
if(a == )return ;
return inv(m%a,m)*(m-m/a)%m;
}
int main()
{
int n,m,k,i,j,cnt,t;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
memset(num,,sizeof(num));
for(i=;i<n;i++){
I(a[i]);
num[a[i]]++;
}
c[n-k]=;
for(i=n-k+;i<=n;i++) c[i]=c[i-]*i%M*inv(i-(n-k),M)%M;
for(i=m;i>=;i--){
cnt=;sum=;
for(j=;i*j<=m;j++){
cnt+=num[i*j];
if(j>) sum=(sum+an[i*j])%M;
}
t=m/i;
if(t==){
if(cnt==n-k) an[i]=;
else an[i]=;
continue;
}
if(cnt<n-k){
an[i]=;
continue;
}
an[i]=c[cnt]*pows(t,n-cnt)%M*pows(t-,cnt-(n-k))%M;
an[i]=((an[i]-sum)%M+M)%M;
}
for(i=;i<=m;i++){
printf("%I64d",an[i]);
if(i<=m-) printf(" ");
else printf("\n");
}
}
return ;
}
hdu 4675 GCD of Sequence的更多相关文章
- 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 ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 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, -, ...
- HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解
题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...
- hdu4675 GCD of Sequence 莫比乌斯+组合数学
/** 题目:hdu4675 GCD of Sequence 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给定n个数的a数组,以及m,k: ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
随机推荐
- C# 添加,修改,删除文件夹/文件集合
C#追加文件 StreamWriter sw = File.AppendText(Server.MapPath(".")+"\\myText.txt"); sw ...
- easyui扩展-日期范围选择.
参考: http://www.5imvc.com/Rep https://github.com/dangrossman/bootstrap-daterangepicker * 特性: * (1)基本功 ...
- 降kipmi0的CPU
echo 100 >/sys/module/ipmi_si/parameters/kipmid_max_busy_us
- HTML5之拖放
- Draggable 标签 文件拖放 99年IE5开始,05后所有浏览器支持(除了opera) <li id=be draggable=true ondragstart="star ...
- Transact-SQL 存储过程(c#调用执行)
1. Microsoft SQL Server Management Studio 中创建 存储过程 1.1 借助模板资源管理器中的Stored Procedure模板进行修改创建 1.2 直接新建查 ...
- 在Windows 7下面IIS7的安装和 配置ASP的正确方法
在Windows 7下如何安装IIS7,以及IIS7在安装过程中的一些需要注意的设置,以及在IIS7下配置ASP的正确方法. 一.进入Windows 7的 控制面板,选择左侧的打开或关闭Windows ...
- Mac下使用Web服务器性能/压力测试工具webbench、ab、siege
Web开发,少不了的就是压力测试,它是评估一个产品是否合格上线的基本标准,下面我们来一一剖析他们的使用方式. 测试前,前面先把系统的端口限制数改大,看看Mac下面的默认限制 ulimit -a ope ...
- php header头信息 举例
发布:sunday01 来源:Net [大 中 小] 转自:http://www.jbxue.com/article/6915.html 用于演示PHP header()函数用法的代码,介 ...
- cxgrid GridMode 等于 True 时的一些问题。
When using grid mode, the data controller loads a fixed number of dataset records into memory. The n ...
- sublime text2 配置php调试环境
步骤一: 首先确保你电脑安装了php,并把php设置到环境变量里了. 步骤二: 点击 sublime_text的“工具”->"编译系统"->"编译新系统&qu ...