UVA10375 Choose and divide 质因数分解
质因数分解:
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 divideThe binomial coefficient C(m,n) is defined as
Given four natural numbers p, q, r, and s, compute the the result of dividing C(p,q) by C(r,s). The InputInput consists of a sequence of lines. Each line contains four non-negative integer numbers giving values for p, q, r, and s, respectively, separated by a single space. All the numbers will be smaller than 10,000 with p>=q and r>=s. The OutputFor 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
Output for Sample Input
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 |
![]() |
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- const int maxn=10010;
- int p,q,r,s;
- int prime[maxn],pn;
- long long int fnum[maxn],pnum[maxn];
- bool vis[maxn];
- void pre_init()
- {
- memset(vis,true,sizeof(vis));
- for(int i=2; i<maxn; i++)
- {
- if(i%2==0&&i!=2) continue;
- if(vis[i]==true)
- {
- prime[pn++]=i;
- for(int j=2*i; j<maxn; j+=i)
- {
- vis[j]=false;
- }
- }
- }
- }
- void fenjie_x(int x,long long int* arr)
- {
- for(int i=0; i<pn&&x!=1; i++)
- {
- while(x%prime[i]==0)
- {
- arr[i]++;
- x/=prime[i];
- }
- }
- }
- void fenjie(int x,long long int* arr)
- {
- for(int i=2; i<=x; i++)
- fenjie_x(i,arr);
- }
- void jianshao()
- {
- for(int i=0; i<pn; i++)
- {
- long long int Min=min(fnum[i],pnum[i]);
- fnum[i]-=Min;
- pnum[i]-=Min;
- }
- }
- int main()
- {
- pre_init();
- while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF)
- {
- memset(pnum,0,sizeof(pnum));
- memset(fnum,0,sizeof(fnum));
- fenjie(p,pnum);fenjie(s,pnum);fenjie(r-s,pnum);
- fenjie(q,fnum);fenjie(r,fnum);fenjie(p-q,fnum);
- jianshao();
- double ans=1.;
- for(int i=0; i<pn; i++)
- {
- while(pnum[i]--)
- {
- ans*=1.*prime[i];
- }
- while(fnum[i]--)
- {
- ans/=1.*prime[i];
- }
- }
- printf("%.5lf\n",ans);
- }
- return 0;
- }
版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss
UVA10375 Choose and divide 质因数分解的更多相关文章
- 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 ...
- uva10375 Choose and divide
唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- 关于Miller-Rabin与Pollard-Rho算法的理解(素性测试与质因数分解)
前置 费马小定理(即若P为质数,则\(A^P\equiv A \pmod{P}\)). 欧几里得算法(GCD). 快速幂,龟速乘. 素性测试 引入 素性测试是OI中一个十分重要的事,在数学毒瘤题中有着 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 求n!质因数分解之后素数a的个数
n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...
- AC日记——质因数分解 1.5 43
43:质因数分解 总时间限制: 1000ms 内存限制: 65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...
- 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛
4514: [Sdoi2016]数字配对 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 726 Solved: 309[Submit][Status ...
- 整数分解 && 质因数分解
输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...
- 【暑假】[数学]UVa 10375 Choose and divide
UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...
随机推荐
- 消息队列(Message Queue)基本概念(转)
背景 之前做日志收集模块时,用到flume.另外也有的方案,集成kafaka来提升系统可扩展性,其中涉及到消息队列当时自己并不清楚为什么要使用消息队列.而在我自己提出的原始日志采集方案中不适用消息队列 ...
- iOS 获取高速随机路径sandbox目录
NSLog(@"%@", NSHomeDirectory());//沙盒主目录 NSLog(@"%@", NSTemporaryDirectory());//砂 ...
- C# 引用类型与值类型的区别
//引用类型(使用了class) class SomeRef{public Int32 x;} //值类型(使用了struct) struct SomeVal{public Int32 x;} sta ...
- Quick StateMachine状态机
状态机quick中是一个亮点,假设我们做一款RPG游戏,一个角色通常会拥有idle,attack,walk.run,death这些状态,假设游戏角色的状态採用分支条件推断的话.会造成很庞大而难以维护. ...
- C++ - Identifier not found
This is because forward declaration in C++: Compiler needs to know function prototype when functi ...
- 递归遍历XML所有节点
package xml; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.DocumentEx ...
- 玩转html5(二)----用canvas结合脚本在画布上画简单的图(html5又一强大功能)
在html5中可以使用canvas标签在画布上画图,先直接上代码,这篇文章先简单介绍一下canvas的使用方法,简单画几个圆,矩形,三角形,写字. 在代码中均给出了注释,在这里特别强调的一点是:使用c ...
- Android锁定屏幕或关闭状态-screen,高速按两次音量向下键来实现拍摄功能(1.1Framework在实现的形式层广播)
思想的实现: WindowManagerService循环读取下面的关键信息和分发形式.在PhoneWindowManager.interceptKeyBeforeQueueing方法中进行消 ...
- LayoutInflater使用
在实际工作中,事先写好的布局文件往往不能满足我们的需求,有时会依据情况在代码中自己定义控件,这就须要用到LayoutInflater.LayoutInflater在Android中是“扩展”的意思,作 ...
- 两个堆叠fragment,上层fragment响应于降低fragment的button点击事件补救措施
加入onViewCreated的Touch事件监听, 以解决叠在一起的fragment上层响应下层的button点击事件解决方法 @Override public void onViewCreated ...