Codeforces 396A 数论,组合数学
题意:给一个a数组,求b 数组的方案数,但是要求两者乘积相同。
分析:
不可能将它们乘起来,对于每个数质因数分解,得到每个质因子个数,遍历这些质因子,将某个质因子放到 对应的盒子里面,可以不放,方案数就是一个组合数,用插板法。
这里的素数板子挺好的,一方面可以用来判断,一方面存起来。
组合数,可以考虑用乘法逆元。
每个质因子个数hash一下。
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + ;
#define N 50009
typedef long long ll; const int maxnn = +;
int C[maxnn][]; void init() {
memset(C, , sizeof(C));
C[][] = ;
C[][] = C[][] = ;
for(int i = ; i < maxnn; ++i)
{
C[i][] = C[i][i] = ;
for(int j = ; j < i; ++j)
{
C[i][j] = (C[i-][j-] + C[i-][j]) % MOD;
}
}
} bool vis[];
int primes[];
int num_prime;
int get_primes (int m) { //获取一定范围内的素数
memset(vis,,sizeof(vis));
for(int i=;i<m;i++) {
if(!vis[i])
primes[num_prime++]=i;
for(int j=;j<num_prime && i*primes[j]<m;j++) {
vis[i*primes[j]]=;
if(!(i%primes[j]))
break;
}
}
return num_prime;
} std::map<int, int> mp; void divide(int x) {
int temp = (int)sqrt(x*1.0);
for(int i=;i<num_prime;i++) {
if(primes[i]>temp) break;
while(x%primes[i]==) {
mp[primes[i]]++;
x /=primes[i];
}
}
if(x!=)
mp[x]++;
} int main(int argc, char const *argv[])
{
mp.clear();
init();
get_primes(N);
int n,x;
scanf("%d",&n);
for(int i=;i<n;i++) {
scanf("%d",&x);
divide(x);
} ll ans= ;
std::map<int, int> ::iterator p; for(p = mp.begin();p!=mp.end();p++) {
int k = p->second; ans = ans * C[k+n-][n-] % MOD;
} printf("%lld\n", ans); return ;
}
Codeforces 396A 数论,组合数学的更多相关文章
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field【数论/组合数学】
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 223C Partial Sums 数论+组合数学
题意非常easy,求不是那么好求的,k非常大 要操作非常多次,所以不可能直接来的.印象中解决操作比較多无非线段树 循环节 矩阵 组合数等等吧,这道题目 也就仅仅能多画画什么 的了 就以第一个案例为主吧 ...
- CodeForces 300C --数论
A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- Codeforces 264B 数论+DP
题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream& ...
- Colorful Bricks CodeForces - 1081C ( 组合数学 或 DP )
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in t ...
- Codeforces 15E Triangles - 组合数学
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby fores ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- CodeForces 1202F(数论,整除分块)
题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \fr ...
随机推荐
- oracle 笔记---(五)__内存管理
###查看连接池的信息 select connection_pool,status,maxsize from dba_cpool_info
- oracle sql命令
set time on; 设置时间 alter table flashback_test enable row movement; 开启行移 select * from flashback_test ...
- DNS服务器设置
1,域名解析:ip能够访问,但是域名不能访问. 2,配置好网络之后,切换到命令行模式,配置好的网络便不能用了. 具体方法: 打开vim /etc/sysconfig/network-scripts/i ...
- BJFU 1551 ——delightful world——————【暴搜】
delightful world 时间限制(C/C++):20000MS/30000MS 运行内存限制:65536KByte总提交:33 测试通过:10 描述 ...
- win 环境下 node.js环境变量
在win 环境下 node.js环境变量有两种情况: (1)开发环境(development):开发环境是程序猿们专门用于开发的服务器,配置可以比较随意, 为了开发调试方便,一般打开全部错误报告. ...
- 前端参数统一校验工具类ValidParamUtils
1,前端参数不可信,对于后端开发人员来说应该是一条铁律,所以对于前端参数的校验,必不可少,而统一的前端参数校验工具,对我们进行参数校验起到事半功倍的效果 2,统一参数校验工具ValidParamUti ...
- PAT 1062 Talent and Virtue
#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #i ...
- phpmyadmin杂记
看着坑爹的教程..我老是报错我也很无奈啊 以下几项必改 $cfg['blowfish_secret'] = ' ';//这里引号内是空格,实际上可以是任意内容, $cfg['Servers'][$i] ...
- Stage4--Python面向对象
说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...
- Flexviewer调用特定的widget
Flexviewer调用特定的widget: 之前一直是自己添加个固定的key来调用widget 但是后来发现框架早就为你写好啦调用widget的方法 在WidgetManager中有个 public ...