http://codeforces.com/contest/397/problem/C

给出n个数字,m = a[1] * a[2] * a[3] ... * a[n]

要求把m分成n个不一样的乘积,求方案数。

就是35分成2分的话,1 * 35 。35 * 1。5 * 7。7 * 5

首先数字很大,表示出来是不可能的。

考虑储存它的质因数,例如12。 12 = 2 * 2 * 3

如果要分成4分的话,首先对每一种质因数放。

例如2,有2个,可以表示为(4份)

2 * 2 * 1 * 1

2 * 1 * 2 * 1

......

4 * 1 * 1 * 1

..........

这是一个经典的组合数学问题,n个球,放在m个箱子,可以空,可以重叠。一共有C(n + m - 1, m - 1)种。

这里空的用了1来表示。

然后不对呀,这不是12的分解情况,它还有一个质因子嘛,3.

分成

3 * 1 * 1 * 1

1 * 3 * 1 * 1

1 * 1 * 3 * 1

1 * 1 * 1 * 3

,然后种数相乘,就是答案,为什么呢?比如(2 * 2 * 1 * 1) X (3 * 1 * 1 * 1) = (6 * 2 * 1 * 1),是一种情况。

因为有500个数字,如果每个数字都是2^30次方,一共有15000个2,但是格子最多500个。

可以预处理组合数C[15000][500]即可,不会爆内存,

一开始一直re,是我自己没分析好。、

最后也没预处理,因为没想到用C[15000][500]这样, 用的是逆元。我太水了太渣了

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
#define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
map<int, int>mp;
const int MOD = 1e9 + ;
LL quick_pow(LL a, LL b, LL MOD) { //求解 a^b%MOD的值
LL base = a % MOD;
LL ans = ; //相乘,所以这里是1
while (b) {
if (b & ) {
ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
}
base = (base * base) % MOD; //notice。注意这里,每次的base是自己base倍
b >>= ;
}
return ans;
}
LL C(LL n, LL m, LL MOD) {
if (n < m) return ; //防止sb地在循环,在lucas的时候
if (n == m) return ;
LL ans1 = ;
LL ans2 = ;
LL mx = max(n - m, m); //这个也是必要的。能约就约最大的那个
LL mi = n - mx;
for (int i = ; i <= mi; ++i) {
ans1 = ans1 * (mx + i) %MOD;
ans2 = ans2 * i % MOD;
}
return (ans1 * quick_pow(ans2, MOD - , MOD) % MOD); //这里放到最后进行,不然会很慢
} void work() {
mp.clear();
int n;
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
int x;
scanf("%d", &x);
int end = (int)sqrt(x + 0.5);
for (int j = ; j <= end; ++j) {
if (x % j == ) {
mp[j]++;
x /= j;
while (x % j == ) {
mp[j]++;
x /= j;
}
end = (int)sqrt(x + 0.5);
}
}
if (x != ) mp[x]++;
}
LL ans = ;
for (map<int, int> :: iterator it = mp.begin(); it != mp.end(); ++it) {
// cout << it->first << " " << it->second << endl;
int val = it->second;
// if (val > maxn) while(1);
// ans *= C[val + n - 1][n - 1];
ans *= C(val + n - , n - , MOD);
ans %= MOD;
}
printf("%I64d\n", ans);
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

C. On Number of Decompositions into Multipliers 组合数学的更多相关文章

  1. Codeforces396A - On Number of Decompositions into Multipliers

    Portal Description 给出\(n(n\leq500)\)个\([1,10^9]\)的数,令\(m=\prod_{i=1}^n a_i\).求有多少个有序排列\(\{a_n\}\),使得 ...

  2. cf C On Number of Decompositions into Multipliers

    题意:给你n个数,然后把这个n个数的乘积化成n个数相乘,可以化成多少个. 思路:分解质因数,求出每一个质因子的个数,然后用组合数学中隔板法把这些质因子分成n分,答案就是所有质因子划分成n份的情况的乘积 ...

  3. Codeforces Round #232 (Div. 1)

    这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...

  4. Codeforces Round #232 (Div. 1) A 解题报告

    A. On Number of Decompositions into Multipliers 题目连接:http://codeforces.com/contest/396/problem/A 大意: ...

  5. Codeforces Round #232 (Div. 2) C

    C. On Number of Decompositions into Multipliers time limit per test 1 second memory limit per test 2 ...

  6. POJ3252——Round Number(组合数学)

    Round Numbers DescriptionThe cows, as you know, have no fingers or thumbs and thus are unable to pla ...

  7. poj 1019 Number Sequence 【组合数学+数字x的位宽函数】

    题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total ...

  8. poj3252-Round Number 组合数学

    题目: Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8492   Accepted: 2963 ...

  9. 2019长安大学ACM校赛网络同步赛 J Binary Number(组合数学+贪心)

    链接:https://ac.nowcoder.com/acm/contest/897/J 来源:牛客网 Binary Number 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32 ...

随机推荐

  1. 记录 Linux分析apache日志获取最多访问的前10个IP

    摘自: http://blog.csdn.net/tanga842428/article/details/52856413

  2. javabean学习

    javabean是一种可重复使用且跨平台的软件组件.他可以分为:客户界面组件(UI,user interface)和没有用户界面,主要负责处理事务(如,数据处理.操作数据库等)地javabean ja ...

  3. ansible管理windows实践

    一.前言 近期打算搞搞自动部署,因为是windows服务器,一些工具和系统支持都不是太好.最后发现ansible比较火,最重要的是他支持windows.本文主要就ansible 在windows使用环 ...

  4. AtrousConvolution和dilated convolution

    唉,真烦哪些炒概念的,把整个世界都给弄乱了. 这里说一下dilated convolution和atrous convolution. 这两种是一样的,至少keras源码中是一样的.在keras中调用 ...

  5. [练习]使用dx.bat、dexdump.exe、javap、Baksmali

    PART0 这几个工具的关系可以这样描述: 用例: public class Hello { public int foo(int a , int b ) { return (a+b) * (a-b) ...

  6. object_test.py

    #方法,属性,私有化加双下划线 ''' __a 从外部无法访问,但是类的内部可以访问.实际上还是能在类外访问这些私有方法,尽管不应该这么做:s._A__a 如果不需要使用这种方法但是又不行让其他对象不 ...

  7. [ZJOI 2013] K大数查询

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3110 [算法] 整体二分 + 线段树 时间复杂度 : O(NlogN ^ 2) [代 ...

  8. Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone.

    Exception in thread “main” java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecogn ...

  9. 如何应用AutoIt,把局域网中所有的机器名展示在一个combox中?

    有时候,我们会遇到以下情况: 你想与局域网中的某台机器建立连接,你就需要输入对方的机器名. 现在我比较懒,我不想输入对方的机器名,或者对方的机器名很难记住,那怎么办呢? 那就做一个combox在页面上 ...

  10. C++之萃取技术(traits)

    为什么需要类型萃取(特化) 前面我们提到了迭代器,它是一个行为类似于smart pointer之类的东西,主要用于对STL容器中的对象进行访问,而且不暴露容器中的内部结构,而迭代器所指对象的型别称为该 ...