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))).

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <set>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstring>
  10. #include <functional>
  11. #include <cmath>
  12. typedef long long ll;
  13. using namespace std;
  14. const ll mod = ;
  15. map<ll,ll> cnt;
  16.  
  17. int n;
  18. ll a[];
  19. ll c[][];
  20. int main(){
  21. freopen("in.txt","r",stdin);
  22. ios::sync_with_stdio();
  23. c[][] = ;
  24. for(int i=;i<;i++){
  25. for(int j=;j<=min(i,);j++){
  26. if(j== || j==i)
  27. c[i][j] = ;
  28. else
  29. c[i][j] = ( c[i-][j-] +c[i-][j] )%mod;
  30. }
  31. }
  32. cin>>n;
  33. for(int i=;i<n;i++){
  34. cin>>a[i];
  35. }
  36.  
  37. for(int i=;i<n;i++){
  38.  
  39. for(ll j=;j*j<=a[i];j++){
  40.  
  41. if(a[i]%j==){
  42. ll tmp = ;
  43. while(a[i]%j==){
  44. a[i]/=j;
  45. tmp++;
  46.  
  47. }
  48. cnt[j]+=tmp;
  49.  
  50. }
  51.  
  52. }
  53. if(a[i]!=)
  54. cnt[a[i]]++;
  55.  
  56. }
  57.  
  58. ll ans = ;
  59.  
  60. for(map<ll,ll>::iterator i = cnt.begin();i!=cnt.end();i++){
  61. ll cc =(*i).second;
  62.  
  63. ans = (ans*c[cc+n-][n-])%mod;
  64. }
  65.  
  66. cout<<ans%mod<<endl;
  67. return ;
  68. }

Codeforces Round #232 (Div. 1) A 解题报告的更多相关文章

  1. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  2. [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)

    题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...

  3. Codeforces Round #232 (Div. 2) B. On Corruption and Numbers

    题目:http://codeforces.com/contest/397/problem/B 题意:给一个n ,求能不能在[l, r]的区间内的数字相加得到, 数字可多次重复.. 比赛的时候没有想出来 ...

  4. Codeforces Round #232 (Div. 1)

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

  5. 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 ...

  6. Codeforces Round #231 (Div2) 迟到的解题报告

    题目A: 给一个火柴等式,可以从左边移动一根到右边,也可以从右边移到左边,但是不能移动“+”,”=“的火柴, 而且加法里面的数都要大于0(很重要的条件),基本上注意到这点的都过了,没注意的都被HACK ...

  7. CodeForce---Educational Codeforces Round 3 The best Gift 解题报告

    对于这题笔者认为可以用数学排列来算,但是由于笔者很懒所以抄了一段大神的代码来交个大家了, 这位大神的基本想法就是通过记录各类书的数量,再暴力破解: 下面贴出这位大神的代码吧: #include< ...

  8. 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 ...

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

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

随机推荐

  1. HTML5 离线缓存

    离线资源缓存  为了能够让用户在离线状态下继续访问 Web 应用,开发者需要提供一个 cache manifest 文件.这个文件中列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地. ...

  2. 016_openxml_forxml

    016_openxml_forxml --openxml*********************************************************************** ...

  3. Android学习----打印日志Log

    Log.v(tag,msg);所有内容 Log.d(tag,msg);debug Log.i(tag,msg);一般信息 Log.w(tag,msg);警告信息 Log.e(tag,msg);错误信息 ...

  4. oracle删除用户所有的表

    删除用户所有的表,带有级联关系: --创建存储过程 CREATE OR REPLACE PROCEDURE DROPTABLES IS V_SQL ); CURSOR CUR IS SELECT TA ...

  5. js 获取页面高度和宽度(兼容 ie firefox chrome),获取鼠标点击位置

    <script> //得到页面高度 var yScroll = (document.documentElement.scrollHeight >document.documentEl ...

  6. mongoDB之用户及权限设置

    之前用MongoDB没有设置用户和权限,一直都是本机应用程序连接MongoDB.在服务器上部署后对外没有开数据库连接端口,本机应用程序连接再开放应用程序端口供外部访问. 我部署的环境是ubuntu 1 ...

  7. jquery easy ui 学习 (7) TreeGrid Actions

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. IOS开发----委托机制

    委托模式从GoF装饰模式.适配器模式和模板方法等演变过来,几乎每一个应用都会或多或少的用到委托模式. 在古希腊有一个哲学家,他毕生只做三件事情:“睡觉”.“吃饭”.和“工作”.为了更好的生活,提高工作 ...

  9. Boost使用笔记(Smart_ptr)

    我是Word写的,复制过来实在懒得在排版了,有兴趣的朋友可以去我的百度文库看,谢谢 http://wenku.baidu.com/view/34e485e2f61fb7360b4c653e.html ...

  10. k-近邻算法理解

    左图中,绿色圆要被决定赋予哪个类,是红色三角形还是蓝色四方形?如果K=3,由于红色三角形所占比例为2/3,绿色圆将被赋予红色三角形那个类,如果K=5,由于蓝色四方形比例为3/5,因此绿色圆被赋予蓝色四 ...