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的更多相关文章

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

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

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

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

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

  4. UVA10375 Choose and divide 质因数分解

    质因数分解: Choose and divide Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  5. UVA 10375 Choose and divide【唯一分解定理】

    题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...

  6. uva10375 Choose and divide

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

  7. UVa 10375 (唯一分解定理) Choose and divide

    题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...

  8. UVA 10375 Choose and divide

    n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...

  9. UVa 10375 - Choose and divide(唯一分解定理)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  10. Choose and divide(唯一分解定理)

    首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...

随机推荐

  1. java 读取word

    读取word文件 import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import org ...

  2. SQL 索引篇

    索引介绍: 1.索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 数据库索引好比是一本书前面的目录, SQL Server的B树结构 2.加快数据库的查询速 ...

  3. Java泛型Object和?区别

    在写spark streamming读取kafka latest offset的时候,有一下语句: Map<TopicAndPartition, Object> latestOffsets ...

  4. idea工程jdk设置问题

    经常用idea的朋友,会遇到一个问题,那就是你在单测的时候,会报一个jdk的错,截图如下: 我的解决方案是在pom.xml里配置一个节点: <properties> <maven.c ...

  5. cocos2d-x win7 部署

    1. 安装 下载python  https://www.python.org/downloads/release/python-279/ 2.从官网下载cocos2d-x  http://www.co ...

  6. 全志A33平台编译linux(分色排版)V1.1

    全志A33平台编译linux 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/13 10:41 版本:V1.1 (一)解压缩lichee备用 ...

  7. get、post、put、delete、head请求方式

    对资源的增,删,改,查操作,其实都可以通过GET/POST完成,不一定要用PUT和DELETE. 一:Jersey框架,实现了restful风格,常用的注解@GET.@POST.@PUT.@DELET ...

  8. scroll的应用

    jQuery(document).ready(function($){ $('#shang').click(function(){ $('html,body').animate({scrollTop: ...

  9. 解决 HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException:

    HTTP Status 500 - Unable to show problem report: freemarker.core.InvalidReferenceException: The foll ...

  10. QQ应用前景与范围文档

    QQ软件 前景与范围文档       当前版本: 版本1 作   者: 李飞 完成日期: 2013年11月3日 1.  业务需求 1.1 应用背景 20世纪后期网络的应用和21世纪的飞速发展,网络已经 ...