HDU 4390 组合数学&数论
来源:互联网 发布:手机淘宝阿里旺旺在哪 编辑:程序博客网 时间:2024/06/05 12:06
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4390
Number Sequence
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1067 Accepted Submission(s): 428
Problem Description
Given a number sequence b1,b2…bn.
Please count how many number sequences a1,a2,...,an satisfy the condition that a1*a2*...*an=b1*b2*…*bn (ai>1).
Please count how many number sequences a1,a2,...,an satisfy the condition that a1*a2*...*an=b1*b2*…*bn (ai>1).
Input
The input consists of multiple test cases.
For each test case, the first line contains an integer n(1<=n<=20). The second line contains n integers which indicate b1, b2,...,bn(1<bi<=1000000, b1*b2*…*bn<=1025).
For each test case, the first line contains an integer n(1<=n<=20). The second line contains n integers which indicate b1, b2,...,bn(1<bi<=1000000, b1*b2*…*bn<=1025).
Output
For each test case, please print the answer module 1e9 + 7.
Sample Input
23 4
Sample Output
4HintFor the sample input, P=3*4=12.Here are the number sequences that satisfy the condition:2 63 44 36 2
Source
2012 Multi-University Training Contest 10
将所有的b[i]进行素因子分解,则a和b的因子是完全一致的。
剩下的便是将所有b的因子,分给a
我们考虑某个素因子pi,如果有ci个,便成了子问题将ci个相同的物品放入到n个不同的容器中,种数为多少
但是要求ai>1,也就是容器不能为空,这是个问题。
我们考虑的是什么的情况,然后减去假设有一个确定是空的情况,发现可以用容斥原理解决
将m个物品放到到不同的n个容器中,结果为c(n+m-1,n-1)
#include<iostream>#include<cstdio>#include<cstring>#include<vector>using namespace std;#define LL long long#define MOD 1000000007int n;LL C[501][501];LL cnt[1000001];void init(){ C[0][0]=1; for(int i=1;i<501;i++){ C[i][0]=C[i][i]=1; for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD; }}void doit(int x){ for(int i=2;i*i<=x;i++){ while(x%i==0){ x/=i; cnt[i]++; } } if(x>1)cnt[x]++;}vector<LL>p;void solve(){ p.clear(); for(int i=0;i<1000001;i++) if(cnt[i])p.push_back(cnt[i]); int len=p.size(); LL ans=1; for(int i=0;i<len;i++) ans=ans*C[p[i]+n-1][n-1]%MOD; for(int i=1;i<n;i++){ LL tmp=C[n][i]; for(int j=0;j<len;j++) tmp=tmp*C[p[j]+n-i-1][n-i-1]%MOD; if(i&1)ans=((ans-tmp)%MOD+MOD)%MOD; else ans=(ans+tmp)%MOD; } printf("%I64d\n",ans);}int main(){ init(); while(~scanf("%d",&n)){ memset(cnt,0,sizeof cnt); for(int i=0;i<n;i++){ int x;scanf("%d",&x); doit(x); } solve(); } return 0;}
0 0
- HDU 4390 组合数学&数论
- HDU 3944 组合数学+数论
- hdu 4790 数论 实现 组合数学
- hdu 3944 DP? 组合数学与数论的结合
- HDU 4497 GCD and LCM (数论&组合数学)
- poj 3252 组合数学,数论
- 数论&&组合数学_模板
- HDU 1695 GCD (数论-整数和素数,组合数学-容斥原理)
- HDU 1695 GCD (数论-整数和素数,欧拉函数,组合数学-容斥原理)
- HDU 3240 Counting Binary Trees [卡特兰数] 【数论+组合数学】
- HDU 3240 Counting Binary Trees(组合数学-卡特兰数,数论-整数快速幂,数论-求逆元)
- hdu 4390 容斥组合数学
- hdu 4373 组合数学
- hdu 3944 组合数学
- hdu 4045 组合数学
- HDU -1261 组合数学。
- HDU Candy(数学 组合)
- HDU 1027 组合数学
- 利用.pbk来实现ADSL开机自动拨号
- 安卓基础 论MediaPlayer的应用(三)
- linux下计时
- offset
- 三维几何之求空间俩线段的公垂线,以及分数类
- HDU 4390 组合数学&数论
- Hdu 5229 ZCC loves strings(简单题)
- 新东方教育
- gnome 3 的几个桌面扩展
- 不要在构造函数和析构函数中调用虚函数
- 程序的内存布局——函数调用栈的那点事
- NoSQL数据库笔谈
- 根据二叉树前序中序输出后序和根据二叉树后序中序生成前序
- Android实战技巧之三十二:Android Studio中的源代码管理