HDU-4675 GCD of Sequence 数学
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675
题意:给一个大小为N的数列a[i],然后一个数M以及一个数K,要你求得一个数列b[i],其中b[i]有K个数与a[i]中的不相同,使得gcd(b[i])=j。对于每个 j ,求出满足的b[i]的个数。。
首先我们统计数列a[i]每个数的个数,假设现在求gcd(b[i])=j,那么可以在t=M/j的时间内求出 j 的倍数的个数cnt。那么就相当于在cnt个中选择N-K个不变C(cnt,N-K),在剩下的 j 的倍数中有(t-1)^(cnt-t)种,非 j 的倍数中有t^(N-cnt)种,那么就是C(cnt,N-K)*(t-1)^(cnt-t)*t^(N-cnt)。这里求出的是gcd(b[i])为 j 的倍数的情况,还要减去2*j,3*j...的数目,因此 j 从M开始倒推就可以了,减去ans[2*j],ans[3*j]...
//STATUS:C++_AC_1796MS_6144KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const LL MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e50;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End LL C[N],ans[N];
int cnt[N];
int n,m,k; void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
if(!b){d=a;x=;y=;}
else {exgcd(b,a%b,d,y,x);y-=x*(a/b);}
} LL inv(LL a)
{
LL d,x,y;
exgcd(a,MOD,d,x,y);
return (x+MOD)%MOD;
} LL mulpow(LL n,int m)
{
LL ret=;
for(;m;m>>=){
if(m&)ret=(ret*n)%MOD;
n=(n*n)%MOD;
}
return ret;
} int main(){
// freopen("in.txt","r",stdin);
int i,j,a,tot,t,p;
LL s;
while(~scanf("%d%d%d",&n,&m,&k))
{
C[t=n-k]=;
for(i=t+;i<=n;i++){
C[i]=(i*C[i-]%MOD*inv(i-t))%MOD;
}
mem(cnt,);
for(i=;i<n;i++){
scanf("%d",&a);
cnt[a]++;
}
for(i=m;i>=;i--){
tot=cnt[i];s=;
for(j=i+i;j<=m;j+=i){
tot+=cnt[j];
s=(s+ans[j])%MOD;
}
if(t>tot)ans[i]=;
else {
p=m/i;
ans[i]=(C[tot]*mulpow(p-,tot-t)%MOD*mulpow(p,n-tot))%MOD;
ans[i]=(ans[i]-s+MOD)%MOD;
}
} printf("%I64d",ans[]);
for(i=;i<=m;i++)
printf(" %I64d",ans[i]);
putchar('\n');
}
return ;
}
HDU-4675 GCD of Sequence 数学的更多相关文章
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 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(容斥)
题目链接: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_ ...
- hdu 4675 GCD of Sequence
数学题! 从M到1计算,在计算i的时候,算出原序列是i的倍数的个数cnt: 也就是将cnt个数中的cnt-(n-k)个数变掉,n-cnt个数变为i的倍数. 且i的倍数为t=m/i; 则符合的数为:c[ ...
- HDU 5288 OO’s Sequence [数学]
HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...
- HDU 5902 GCD is Funny 数学
GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...
- hdu 4497 GCD and LCM 数学
GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...
随机推荐
- Slider 滑动条效果
转载自:http://www.cnblogs.com/cloudgamer/archive/2008/12/24/Slider.html 这个滑动条(拖动条)效果,一开始是参考了BlueDestiny ...
- MVC项目总结(别人的好文章)
引用 http://www.cnblogs.com/xling/archive/2012/07/11/2587002.html
- SQLite入门与分析(三)---内核概述(1)
写在前面:从本章开始,我们开始进入SQLite的内核.为了能更好的理解SQLite,我先从总的结构上讨论一下内核,从全局把握SQLite很重要.SQLite的内核实现不是很难,但是也不是很简单.总的来 ...
- winform学习日志(十九)----------真正三层架构之登录
摘要:一:三层构架的基础知识在项目开发的过程中,有时把整个项目分为三层架构,其中包括:表示层(UI).业务逻辑层(BLL)和数据访问层(DAL).三层的作用分别如下: 表示层:为用户提供交互操作界面, ...
- C#操作xml文档,cuid,dategridview显示数据
界面 //所有的数据全部在集合中 //dgv控件绑定List集合,List集合中有User类的对象,对象里有属性,把属性绑定到没列的数据上 dgv.Da ...
- 面试常考的数据结构Java实现
1.线性表 2.线性链表 3.栈 4.队列 5.串 6.数组 7.广义表 8.树和二叉树 的结点),并且,二叉树的子树有左右之分,其次序不能任意颠倒. 二叉树的性质: :在二叉树的第 i 层上至多有2 ...
- [转]vim ruby等的ide设置
使用vim做rails开发,推荐这个 https://github.com/carlhuda/janus 1. vim下的Rails常用插件 首先列出我比较常用的vim插件,基本都是网上提到的哪些.必 ...
- Unity NGUI弧形血条的制作
unity版本:4.6 NGUI版本:3.6. (转载请注明参考链接及作者) 参考链接:http://www.cnblogs.com/louissong/p/3841656.html,作者:博客园 L ...
- 函数fsp_seg_inode_page_find_free
/**********************************************************************//** Looks for an unused segm ...
- bzoj2431:[HAOI2009]逆序对数列
单组数据比51nod的那道题还弱...而且连优化都不用了.. #include<cstdio> #include<cstring> #include<cctype> ...