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. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  2. MySQL使用if判断

    select *,if(sva=1,"男","女") as ssva from taname where sva<>"" 12. ...

  3. C++11之lambda表达式

    lambda表达式源于函数式编程的概念,它可以就地匿名定义目标函数或函数对象,不需要额外写一个命名函数或者函数对象.lambda表达式的类型在C++11中被称为"闭包类型",也可以 ...

  4. 【linux草鞋应用编程系列】_3_ 进程间通信

    一.进程间通信        linux下面提供了多种进程间通信的方法, 管道.信号.信号量.消息队列.共享内存.套接字等.下面我们分别 介绍管道.信号量.消息队列.共享内存.        信号和套 ...

  5. [moka同学笔记]使用composer 安装yii2以及遇到的问题

    [一.Yii2安装过程] 使用composer安装,composer安装请参考其他博客 1.下载 Yii2 高级模板 跟普通模板一样 , 可以通过 Composer 和 github 下载 ,不过官方 ...

  6. python征程2.0(python基础)

    1.python中有一些基本规则的特殊字符. (1)#表示这后的字符为python注释. (2)\n标准的行分隔符. (3)\继续上一行.(也就是过长的语句可以使用反斜杠(\)分解成几行) ) and ...

  7. mysql errno 150

    mysql error Number 1005can't creat table'/test/#sql-640_1.frm'(errno:150)三种可能问题 外键和被引用外键类型不一样,比如inte ...

  8. CSS3与页面布局学习笔记(八)——浏览器兼容性问题与前端性能优化方案

    一.浏览器兼容 1.1.概要 世界上没有任何一个浏览器是一样的,同样的代码在不一样的浏览器上运行就存在兼容性问题.不同浏览器其内核亦不尽相同,相同内核的版本不同,相同版本的内核浏览器品牌不一样,各种运 ...

  9. iframe高度自适应

    前两天在网上看到了一道面试题,问iframe高度自适应的问题.发现自己之前几乎没有关注过iframe的问题,所以在这里记录一下. 原题目是: 页面A的域名是:http://www.taobao.com ...

  10. [deviceone开发]-小草用户分享的Listview停靠的示例

    一.简介 这个例子展示了Listview的多模板,上拉下拉功能,也实现了上下滑动第二行工具栏的停靠功能,值得参考 二.效果图 三.相关下载 https://github.com/do-project/ ...