396AOn Number of Decompositions into Multipliers 组合
来源:互联网 发布:腾讯软件测试待遇 编辑:程序博客网 时间:2024/05/18 02:07
首先将所有的数进行质因子分解,统计每个质数出现的次数。
假设第i个质数Pi出现了m次,则可以转化为将m个相同的球放入n个不同盒子的问题,允许盒子唯恐,即不放球。
那么这个问题解即为C(n+m-1,n-1),求解过程如下:
首先这个问题 等价于 将n+m个相同的球放入n个不同盒子,每个盒子都至少有一个球。
这样隔板法可解,将n+m个球排成一列,然后从n+m-1个缝隙选n-1个插入隔板,这样就将球分为n组,然后从每组中取走一个球。
公式出来了,剩下的就是枚举素数,累乘C(n+m-1,n-1)。
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <cmath>#include <stack>#include <map>#include <ctime>#include <iomanip>#pragma comment(linker,"/STACK:1024000000");#define EPS (1e-6)#define LL long long#define ULL unsigned long long#define _LL __int64#define INF 0x3f3f3f3f#define Mod 1000000007#define mod 1000000007/** I/O Accelerator Interface .. **/#define g (c=getchar())#define d isdigit(g)#define p x=x*10+c-'0'#define n x=x*10+'0'-c#define pp l/=10,p#define nn l/=10,ntemplate<class T> inline T& RD(T &x){ char c; while(!d); x=c-'0'; while(d)p; return x;}template<class T> inline T& RDD(T &x){ char c; while(g,c!='-'&&!isdigit(c)); if (c=='-') { x='0'-g; while(d)n; } else { x=c-'0'; while(d)p; } return x;}inline double& RF(double &x) //scanf("%lf", &x);{ char c; while(g,c!='-'&&c!='.'&&!isdigit(c)); if(c=='-')if(g=='.') { x=0; double l=1; while(d)nn; x*=l; } else { x='0'-c; while(d)n; if(c=='.') { double l=1; while(d)nn; x*=l; } } else if(c=='.') { x=0; double l=1; while(d)pp; x*=l; } else { x=c-'0'; while(d)p; if(c=='.') { double l=1; while(d)pp; x*=l; } } return x;}#undef nn#undef pp#undef n#undef p#undef d#undef gusing namespace std;LL num[510];int pri[30010];bool vis[1000100];int ans[1000100];LL extend_gcd(LL a,LL b,LL &x,LL &y){ if(b==0) { x=1; y=0; return a; } LL gcd=extend_gcd(b,a%b,x,y); LL t=x; x=y; y=t-a/b*x; return gcd;}LL Get_Inverse(LL num){ LL x,y; extend_gcd(num,Mod,x,y); return (x%Mod+Mod)%Mod;}LL Cal(LL n,LL m)//计算组合数C(n,m){ LL t1=1,t2=1; for(LL i=n;i>m;i--) { t1=(t1*i)%Mod; t2=(t2*(i-m))%Mod; } return t1*Get_Inverse(t2)%Mod;}int main(){ int Top,n = 100000,i,j; memset(vis,false,sizeof(vis)); Top = 0; for(i = 2;i <= n; ++i) { if(vis[i] == true) continue; pri[Top++] = i; for(j = i+i;j <= n; j += i) vis[j] = true; } scanf("%d",&n); for(i = 1;i <= n; ++i) scanf("%I64d",&num[i]); for(i = 1;i <= n; ++i) { LL tmp = num[i]; for(j = 0;j < Top; ++j) { while(tmp%pri[j] == 0) tmp /= pri[j]; } if(tmp != 1) pri[Top++] = tmp; } sort(pri,pri+Top); memset(ans,0,sizeof(ans)); for(i = 1;i <= n; ++i) { for(j = 0;j < Top; ++j) { while(num[i]%pri[j] == 0) ans[j]++,num[i] /= pri[j]; } } LL sum = 1; for(i = 0;i < Top; ++i) { (sum *= Cal(ans[i]+n-1,n-1)) %= Mod;; } printf("%I64d\n",sum); return 0;}
0 0
- 396AOn Number of Decompositions into Multipliers 组合
- Codeforces 396A On Number of Decompositions into Multipliers(组合数学)
- codeforces 396A A. On Number of Decompositions into Multipliers(组合数学+数论)
- Codeforces-396A - On Number of Decompositions into Multipliers-组合计数
- 解题报告: Codeforces 396A. On Number of Decompositions into Multipliers 组合
- CF 396A On Number of Decompositions into Multipliers(组合数学)
- CF 396A On Number of Decompositions into Multipliers
- CF 396A On Number of Decompositions into Multipliers
- CodeForce 396A On Number of Decompositions into Multipliers
- CF 396A On Number of Decompositions into Multipliers 解题报告(质因数分解+组合数计算)
- codeforces#232_div2_C On Number of Decompositions into Multipliers 数论 组合计数
- CodeForces 397C On Number of Decompositions into Multipliers(组合数学)
- Codeforces Round #232 (Div. 2) C. On Number of Decompositions into Multipliers 之我为何如此菜
- Multipliers
- Codeforces 615D Multipliers 【组合数学】
- ADMM(alternating direction method of multipliers)
- CodeForces - 615D Multipliers 费马小定理+组合数学
- Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
- Android的事件处理
- ZOJ 3329 One Person Game (概率DP)
- 在光标位置插入内容的jquery实现方式
- Android获取上下文Context
- Working with the Alert Monitor
- 396AOn Number of Decompositions into Multipliers 组合
- [iOS] 进阶。
- Android 开发:初步步骤总结
- 11.4.1 无穷列表
- Oracle常用语句大全
- XML Schema
- 单例模式
- 开博第一篇
- 怎么让service开机启动,并且不能让第三方软件禁止