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 ...
随机推荐
- Visual Leak Detector 2.2.3 Visual C++内存检测工具
Visual Leak Detector是一款免费的.健全的.开源的Visual C++内存泄露检测系统.相比Visual C++自带的内存检测机制,Visual Leak Detector可以显 ...
- POJ2524+并查集
题意简单. 询问n个人的宗教关系. #include<stdio.h> ; int fa[ maxn ]; int vis[ maxn ]; void init( int n ){ ;i& ...
- jsp关于include html、jsp等文件出现乱码问题的解决方案
一般来说使用jsp标签<jsp:include>引入一个jsp文件: ①可以在被引入的jsp中加入:<%@ page contentType="text/html;char ...
- c/c++中一些高级函数的使用
setvbuf 函数名: setvbuf 功 能: 把缓冲区与流相关 用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size ...
- WordPress添加网站图标
如何给WordPress添加网站图标_百度经验 http://jingyan.baidu.com/article/54b6b9c0d549622d583b4788.html 看到很多网站都带有ic ...
- 常用PHP框架功能对比表
自接触PHP开发以来,已使用了不少框架,虽然对每个框架都没有专研至深,但对每一款所使用的PHP框架功能都有一些了解的.至此,本人将大家常用的一些PHP框架功能整理成表,希望对大家在选择PHP框架时,可 ...
- xp宿主机和VMware下Ubuntu12.04共享文件夹
VMware下Windows与Linux共享文件的方法有很多,比如Samba等等,我这里介绍简单地通过设置VMware来达到共享的目的. 打开VMware的设置,在"options" ...
- Complete The Pattern #6 - Odd Ladder
Complete The Pattern #6 - Odd Ladder Task: You have to write a function pattern which creates the fo ...
- 使用Powermock进行单元测试,以及常见问题的处理
1. 引言 在进行单元测试时,经常遇到被测方法依赖外部对象和环境,如需要数据库连接,网络通信依赖等,需要进行大量的初始化工作,这时可以采用powermock+mockito对被测对象进行模拟,通过录放 ...
- python20151125
python exit() python test.py 输入输出 print('2\n2') print(1, 2, 3) name = input() print(':', name) 数据类型和 ...