Choose and divide
The binomial coefficient C(m, n) is defined as C(m, n) = m! (m − n)! n! Given four natural numbers p, q, r, and s, compute the the result of dividing C(p, q) by C(r, s). Input Input 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. 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
10 5 14 9 93 45 84 59 145 95 143 92 995 487 996 488 2000 1000 1999 999 9998 4999 9996 4998
Sample Outpu
t 0.12587 505606.46055 1.28223 0.48996 2.00000 3.99960
唯一分解定理应用
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 10009
#define L 31
#define INF 1000000009
#define eps 0.00000001
/*
唯一分解定理 应用
*/
int prime[MAXN], e[MAXN];
void getprime()
{
memset(prime, false, sizeof(prime));
for (int i = ; i <= MAXN; i++)
{
if (!prime[i])
prime[++prime[]] = i;
for (int j = ; j <= prime[] && prime[j] <= MAXN / i; j++)
{
prime[prime[j] * i] = ;
if (i%prime[j] == ) break;
}
}
}
void add_interger(int n, int d)
{
for (int i = ; i <= prime[]; i++)
{
while (n%prime[i] == )
{
n /= prime[i];
e[i] += d;
}
if (n == ) break;
}
}
void add_factorial(int n, int d)
{
for (int i = ; i <= n; i++)
add_interger(i, d);
}
int main()
{
getprime();
int p, q, r, s;
while (cin >> p >> q >> r >> s)
{
memset(e, , sizeof(e));
add_factorial(p, );
add_factorial(q, -);
add_factorial(p - q, -);
add_factorial(r, -);
add_factorial(s, );
add_factorial(r - s, );
double ans = ;
for (int i = ; i <= prime[]; i++)
ans *= pow(prime[i], e[i]);
printf("%.5lf\n", ans);
}
return ;
}
Choose and divide的更多相关文章
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- 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 ...
- 【暑假】[数学]UVa 10375 Choose and divide
UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...
- UVA10375 Choose and divide 质因数分解
质因数分解: Choose and divide Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- UVA 10375 Choose and divide【唯一分解定理】
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...
- uva10375 Choose and divide
唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- UVa 10375 (唯一分解定理) Choose and divide
题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...
- UVA 10375 Choose and divide
n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n] 其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...
- UVa 10375 - Choose and divide(唯一分解定理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Choose and divide(唯一分解定理)
首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...
随机推荐
- ViewPager(3)用viewpager实现tabhost
1.示例 2.代码 2.1 TabViewPagerMain.java import android.graphics.drawable.Drawable; import android.os.Bun ...
- Android 性能优化(10)网络优化( 6)Optimizing General Network Use
Optimizing General Network Use This lesson teaches you to Compress Data Cache Files Locally Optimize ...
- C# 调用非托管函数
C#通过DllImport可以直接调用Windows中的一些功能.C++中已经编写好的一些方法: DllImport所在的名字空间:System.Runtime.InteropServices; Dl ...
- leetcode221 Maximal Square
思路: dp. 实现: class Solution { public: int maximalSquare(vector<vector<char>>& matrix) ...
- 一次“MySQL server has gone away”故障及其解决
1,问题现象 某次测试发现,程序失去响应.由于程序集成了EurekaLog组件,弹出了错误框.查看其给出的Call Stack信息,发现没有发生线程死锁(DeadLock=0;),问题在于 Wait ...
- Vue.js——router-link阻止click事件
router-link 只能单纯做路由跳转 https://segmentfault.com/q/1010000007896386
- Linux系统调用--getrusage函数详解
Linux系统调用--getrusage函数详解 功能描述: 获得进程的相关资源信息.如:用户开销时间,系统开销时间,接收的信号量等等; 用法: #include <sys/t ...
- 梦想CAD控件安卓交互绘图
在cad使用过程中,动态绘制的使用会使我们绘图速度大大加快.在此演示中,我们绘制了直线.多段线.点.样条线.圆.圆弧.椭圆.椭圆弧等实体. 用户可以在CAD控件视区任意位置绘制直线. 主要用到函数说明 ...
- 16Oracle Database 系统权限和对象权限
Oracle Database 系统权限和对象权限 Oracle中的系统权限和对象权限 DCL 数据控制语言 -- 查看对象的权限 grant / revoke 查看登录用户 Show user 查看 ...
- C# Task详解
1.Task的优势 ThreadPool相比Thread来说具备了很多优势,但是ThreadPool却又存在一些使用上的不方便.比如: ◆ ThreadPool不支持线程的取消.完成.失败通知等交互性 ...