质因数分解:

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

id=19601" class="login ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; border:1px solid rgb(211,211,211); color:blue; font-size:12px!important">Submit Status

Description

Problem D: Choose and divide

The binomial coefficient C(m,n) is defined as

  1. m!
  2. C(m,n) = --------
  3. n!(m-n)!

Given four natural numbers pqr, and s, compute the the result of dividing C(p,q) by C(r,s).

The Input

Input consists of a sequence of lines. Each line contains four non-negative integer numbers giving values for pqr, and s, respectively, separated by a single space. All the numbers will be smaller than 10,000 with p>=q and r>=s.

The Output

For each line of input, print a single line containing a real number with 5 digits of precision in the fraction, giving the number as described above. You may assume the result is not greater than 100,000,000.

Sample Input

  1. 10 5 14 9
  2. 93 45 84 59
  3. 145 95 143 92
  4. 995 487 996 488
  5. 2000 1000 1999 999
  6. 9998 4999 9996 4998

Output for Sample Input

  1. 0.12587
  2. 505606.46055
  3. 1.28223
  4. 0.48996
  5. 2.00000
  6. 3.99960

Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples

Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 6. Mathematical Concepts and Methods

Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Combinatorics :: 

option=com_onlinejudge&Itemid=8&category=405" style="color:blue; text-decoration:none">Binomial
Coefficients


Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Combinatorics :: Binomial
Coefficients




Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 5. Mathematics :: Combinatorics

Root :: Prominent Problemsetters :: Gordon V. Cormack

Submit Status

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int maxn=10010;
  9.  
  10. int p,q,r,s;
  11.  
  12. int prime[maxn],pn;
  13. long long int fnum[maxn],pnum[maxn];
  14. bool vis[maxn];
  15.  
  16. void pre_init()
  17. {
  18. memset(vis,true,sizeof(vis));
  19. for(int i=2; i<maxn; i++)
  20. {
  21. if(i%2==0&&i!=2) continue;
  22. if(vis[i]==true)
  23. {
  24. prime[pn++]=i;
  25. for(int j=2*i; j<maxn; j+=i)
  26. {
  27. vis[j]=false;
  28. }
  29. }
  30. }
  31. }
  32.  
  33. void fenjie_x(int x,long long int* arr)
  34. {
  35. for(int i=0; i<pn&&x!=1; i++)
  36. {
  37. while(x%prime[i]==0)
  38. {
  39. arr[i]++;
  40. x/=prime[i];
  41. }
  42. }
  43. }
  44.  
  45. void fenjie(int x,long long int* arr)
  46. {
  47. for(int i=2; i<=x; i++)
  48. fenjie_x(i,arr);
  49. }
  50.  
  51. void jianshao()
  52. {
  53. for(int i=0; i<pn; i++)
  54. {
  55. long long int Min=min(fnum[i],pnum[i]);
  56. fnum[i]-=Min;
  57. pnum[i]-=Min;
  58. }
  59. }
  60.  
  61. int main()
  62. {
  63. pre_init();
  64. while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF)
  65. {
  66. memset(pnum,0,sizeof(pnum));
  67. memset(fnum,0,sizeof(fnum));
  68. fenjie(p,pnum);fenjie(s,pnum);fenjie(r-s,pnum);
  69. fenjie(q,fnum);fenjie(r,fnum);fenjie(p-q,fnum);
  70. jianshao();
  71. double ans=1.;
  72. for(int i=0; i<pn; i++)
  73. {
  74. while(pnum[i]--)
  75. {
  76. ans*=1.*prime[i];
  77. }
  78. while(fnum[i]--)
  79. {
  80. ans/=1.*prime[i];
  81. }
  82. }
  83. printf("%.5lf\n",ans);
  84. }
  85. return 0;
  86. }

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

UVA10375 Choose and divide 质因数分解的更多相关文章

  1. uva10375 Choose and Divide(唯一分解定理)

    uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...

  2. uva10375 Choose and divide

    唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...

  3. 关于Miller-Rabin与Pollard-Rho算法的理解(素性测试与质因数分解)

    前置 费马小定理(即若P为质数,则\(A^P\equiv A \pmod{P}\)). 欧几里得算法(GCD). 快速幂,龟速乘. 素性测试 引入 素性测试是OI中一个十分重要的事,在数学毒瘤题中有着 ...

  4. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  5. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  6. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

  7. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

  8. 整数分解 && 质因数分解

    输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...

  9. 【暑假】[数学]UVa 10375 Choose and divide

    UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...

随机推荐

  1. 消息队列(Message Queue)基本概念(转)

    背景 之前做日志收集模块时,用到flume.另外也有的方案,集成kafaka来提升系统可扩展性,其中涉及到消息队列当时自己并不清楚为什么要使用消息队列.而在我自己提出的原始日志采集方案中不适用消息队列 ...

  2. iOS 获取高速随机路径sandbox目录

    NSLog(@"%@", NSHomeDirectory());//沙盒主目录 NSLog(@"%@", NSTemporaryDirectory());//砂 ...

  3. C# 引用类型与值类型的区别

    //引用类型(使用了class) class SomeRef{public Int32 x;} //值类型(使用了struct) struct SomeVal{public Int32 x;} sta ...

  4. Quick StateMachine状态机

    状态机quick中是一个亮点,假设我们做一款RPG游戏,一个角色通常会拥有idle,attack,walk.run,death这些状态,假设游戏角色的状态採用分支条件推断的话.会造成很庞大而难以维护. ...

  5. C++ - Identifier not found

     This is because forward declaration in C++: Compiler needs to know function prototype when functi ...

  6. 递归遍历XML所有节点

    package xml; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.DocumentEx ...

  7. 玩转html5(二)----用canvas结合脚本在画布上画简单的图(html5又一强大功能)

    在html5中可以使用canvas标签在画布上画图,先直接上代码,这篇文章先简单介绍一下canvas的使用方法,简单画几个圆,矩形,三角形,写字. 在代码中均给出了注释,在这里特别强调的一点是:使用c ...

  8. Android锁定屏幕或关闭状态-screen,高速按两次音量向下键来实现拍摄功能(1.1Framework在实现的形式层广播)

    思想的实现:     WindowManagerService循环读取下面的关键信息和分发形式.在PhoneWindowManager.interceptKeyBeforeQueueing方法中进行消 ...

  9. LayoutInflater使用

    在实际工作中,事先写好的布局文件往往不能满足我们的需求,有时会依据情况在代码中自己定义控件,这就须要用到LayoutInflater.LayoutInflater在Android中是“扩展”的意思,作 ...

  10. 两个堆叠fragment,上层fragment响应于降低fragment的button点击事件补救措施

    加入onViewCreated的Touch事件监听, 以解决叠在一起的fragment上层响应下层的button点击事件解决方法 @Override public void onViewCreated ...