Codeforces Round #232 (Div. 1) A 解题报告
A. On Number of Decompositions into Multipliers
题目连接:http://codeforces.com/contest/396/problem/A
大意:给定n(n<=500)个数ai(1<=ai<=10^9),得到他们的乘积m,问将m分解成n个数相乘,有多少种方法.
思路:显然每个质因数都是独立的,如果质因数pi出现了ci次,那么把它分到n个数中,就有C(ci+n-1,n-1)种方法,然后把所有因数的答案相乘就是结果。于是我们可以先预处理出来组合数。然后对每个ai进行分解因式,最后的复杂度O(n*sqrt(max(ai))).
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstring>
- #include <functional>
- #include <cmath>
- typedef long long ll;
- using namespace std;
- const ll mod = ;
- map<ll,ll> cnt;
- int n;
- ll a[];
- ll c[][];
- int main(){
- freopen("in.txt","r",stdin);
- ios::sync_with_stdio();
- c[][] = ;
- for(int i=;i<;i++){
- for(int j=;j<=min(i,);j++){
- if(j== || j==i)
- c[i][j] = ;
- else
- c[i][j] = ( c[i-][j-] +c[i-][j] )%mod;
- }
- }
- cin>>n;
- for(int i=;i<n;i++){
- cin>>a[i];
- }
- for(int i=;i<n;i++){
- for(ll j=;j*j<=a[i];j++){
- if(a[i]%j==){
- ll tmp = ;
- while(a[i]%j==){
- a[i]/=j;
- tmp++;
- }
- cnt[j]+=tmp;
- }
- }
- if(a[i]!=)
- cnt[a[i]]++;
- }
- ll ans = ;
- for(map<ll,ll>::iterator i = cnt.begin();i!=cnt.end();i++){
- ll cc =(*i).second;
- ans = (ans*c[cc+n-][n-])%mod;
- }
- cout<<ans%mod<<endl;
- return ;
- }
Codeforces Round #232 (Div. 1) A 解题报告的更多相关文章
- Codeforces Round 319 # div.1 & 2 解题报告
Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...
- [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)
题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...
- Codeforces Round #232 (Div. 2) B. On Corruption and Numbers
题目:http://codeforces.com/contest/397/problem/B 题意:给一个n ,求能不能在[l, r]的区间内的数字相加得到, 数字可多次重复.. 比赛的时候没有想出来 ...
- Codeforces Round #232 (Div. 1)
这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...
- Codeforces Round #232 (Div. 2) D. On Sum of Fractions
D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...
- Codeforces Round #231 (Div2) 迟到的解题报告
题目A: 给一个火柴等式,可以从左边移动一根到右边,也可以从右边移到左边,但是不能移动“+”,”=“的火柴, 而且加法里面的数都要大于0(很重要的条件),基本上注意到这点的都过了,没注意的都被HACK ...
- CodeForce---Educational Codeforces Round 3 The best Gift 解题报告
对于这题笔者认为可以用数学排列来算,但是由于笔者很懒所以抄了一段大神的代码来交个大家了, 这位大神的基本想法就是通过记录各类书的数量,再暴力破解: 下面贴出这位大神的代码吧: #include< ...
- Codeforces Round #232 (Div. 2) On Sum of Fractions
Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest pri ...
- Codeforces Round #232 (Div. 2) C
C. On Number of Decompositions into Multipliers time limit per test 1 second memory limit per test 2 ...
随机推荐
- HTML5 离线缓存
离线资源缓存 为了能够让用户在离线状态下继续访问 Web 应用,开发者需要提供一个 cache manifest 文件.这个文件中列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地. ...
- 016_openxml_forxml
016_openxml_forxml --openxml*********************************************************************** ...
- Android学习----打印日志Log
Log.v(tag,msg);所有内容 Log.d(tag,msg);debug Log.i(tag,msg);一般信息 Log.w(tag,msg);警告信息 Log.e(tag,msg);错误信息 ...
- oracle删除用户所有的表
删除用户所有的表,带有级联关系: --创建存储过程 CREATE OR REPLACE PROCEDURE DROPTABLES IS V_SQL ); CURSOR CUR IS SELECT TA ...
- js 获取页面高度和宽度(兼容 ie firefox chrome),获取鼠标点击位置
<script> //得到页面高度 var yScroll = (document.documentElement.scrollHeight >document.documentEl ...
- mongoDB之用户及权限设置
之前用MongoDB没有设置用户和权限,一直都是本机应用程序连接MongoDB.在服务器上部署后对外没有开数据库连接端口,本机应用程序连接再开放应用程序端口供外部访问. 我部署的环境是ubuntu 1 ...
- jquery easy ui 学习 (7) TreeGrid Actions
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- IOS开发----委托机制
委托模式从GoF装饰模式.适配器模式和模板方法等演变过来,几乎每一个应用都会或多或少的用到委托模式. 在古希腊有一个哲学家,他毕生只做三件事情:“睡觉”.“吃饭”.和“工作”.为了更好的生活,提高工作 ...
- Boost使用笔记(Smart_ptr)
我是Word写的,复制过来实在懒得在排版了,有兴趣的朋友可以去我的百度文库看,谢谢 http://wenku.baidu.com/view/34e485e2f61fb7360b4c653e.html ...
- k-近邻算法理解
左图中,绿色圆要被决定赋予哪个类,是红色三角形还是蓝色四方形?如果K=3,由于红色三角形所占比例为2/3,绿色圆将被赋予红色三角形那个类,如果K=5,由于蓝色四方形比例为3/5,因此绿色圆被赋予蓝色四 ...