UVA - 10375

Choose and divide
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4053   Accepted: 1318

Description

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

            m!

C(m,n) = --------

n!(m-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 Output

0.12587
505606.46055
1.28223
0.48996
2.00000
3.99960

Source


唯一分解定理

太诡异了,uva AC

poj一直TLE,连白书的标解都WA

//
// main.cpp
// poj2613
//
// Created by Candy on 10/20/16.
// Copyright ? 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=1e4+;
int p,q,r,s;
int prime[N],cnt=,e[N],vis[N];
void era(int n){
int m=sqrt(n)+;
for(int i=;i<=m;i++) if(!vis[i])
for(int j=i*i;j<=n;j+=i) vis[j]=;
for(int i=;i<=n;i++) if(!vis[i]) prime[++cnt]=i;
}
inline void mul(int x,int d){//x^d
for(int i=;i<=cnt&&x!=;i++)
while(x%prime[i]==){
x/=prime[i];
e[i]+=d;
}
}
void fac(int x,int d){//printf("%d %d\n",x,d);
for(int i=;i<=x;i++) mul(i,d);
}
inline int fastPow(int a,int b){
int ans=;
for(;b;b>>=,a*=a)
if(b&) ans*=a;
return ans;
}
int main(int argc, const char * argv[]){
era();//cout<<"p";
while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF){
memset(e,,sizeof(e));
fac(p,);
fac(q,-);
fac(p-q,-);
fac(r,-);
fac(s,);
fac(r-s,);
double ans=;
for(int i=;i<=cnt;i++){
if(e[i]>) ans*=(double)fastPow(prime[i],e[i]);
else if(e[i]<) ans/=(double)fastPow(prime[i],-e[i]);
// ans*=pow(prime[i],e[i]);
}
printf("%.5f\n",ans);
} return ;
}

UVA - 10375 Choose and divide[唯一分解定理]的更多相关文章

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

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

  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【唯一分解定理】

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

  4. UVA 10375 Choose and divide(大数的表示)

    紫上给得比较奇怪,其实没有必要用唯一分解定理.我觉得这道题用唯一分解只是为了表示大数. 但是分解得到的幂,累乘的时候如果顺序很奇怪也可能溢出.其实直接边乘边除就好了.因为答案保证不会溢出, 设定一个精 ...

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

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

  6. UVA 10375 Choose and divide

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

  7. Uva 10375 选择与除法 唯一分解定理

    题目链接:https://vjudge.net/contest/156903#problem/E 题意:已知 求:C(p,q)/C(r,s) 其中p,q,r,s都是10^4,硬算是肯定超数据类型的. ...

  8. UVA.10791 Minimum Sum LCM (唯一分解定理)

    UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...

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

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

随机推荐

  1. Xml的简单介绍和Xml格式

    XML 被设计用来结构化.存储以及传输信息.HTML 被设计用来显示数据. 1.XML是什么? 1)XML 指可扩展标记语言(EXtensible Markup Language) 2)XML 是一种 ...

  2. div的显示和隐藏以及点击图标的更改

  3. Bootstrap之表单控件状态

    Bootstrap中的表单控件状态主要有三种:焦点状态,禁用状态,验证状态.   一.焦点状态:该状态告诉用户可输入或选择东西 焦点状态通过伪类“:focus”以实现. bootstrap.css相应 ...

  4. 在PHP语言中使用JSON和将json还原成数组

    在之前我写过php返回json数据简单实例,刚刚上网,突然发现一篇文章,也是介绍json的,还挺详细,值得参考.内容如下 从5.2版本开始,PHP原生提供json_encode()和json_deco ...

  5. 基于小脚丫的ADC081S101 电压采集595数码管显示

    RTL结构图 采集模块运用SPI 通讯 MISO方式收集数据 module ad_collect(input sddata,input rst_n,output reg cs,output reg s ...

  6. Cats(4)- 叠加Free程序运算结果,Stacking monadic result types

    在前面的几篇关于Free编程的讨论示范中我们均使用了基础类型的运算结果.但在实际应用中因为需要考虑运算中出现异常的情况,常常会需要到更高阶复杂的运算结果类型如Option.Xor等.因为Monad无法 ...

  7. php和js中json的编码和解码

    php中 1)编码 $jsonStr = json_encode($array) 2)解码 $arr = json_decode($jsonStr) <?php echo json_encode ...

  8. 安卓模拟器genymotion连接eclipse成功但是不显示其中项目

    安卓模拟器困了我两三天了,原装模拟器比较慢,忍受不了,查到安卓模拟器的神器——genymotion 按照网上的步骤一步步都安装完毕,最后打开后发现,genymotion界面里面没有找到新建的工程, 这 ...

  9. JVM监控工具介绍

    JVM监控工具介绍 VisualVM是一种集成了多个JDK命令行工具的可视化工具,它能为您提供强大的分析能力.所有这些都是免费的!它囊括的命令行工具包括jps,jstat,jmap,jinfo,jst ...

  10. Struts2(1) —— 概述

    1.Struts2框架介绍 Struts2框架是MVC流程框架,适合分层开发,框架应用实现不依赖于Servlet,使用大量的拦截器来处理用户请求,属于无侵入式的设计. 2.Struts2框架的流程原理 ...