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. sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )

    通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下.   其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...

  2. 使用git error: RPC failed; result=22, HTTP code = 411

    使用git提交比较大的文件的时候可能会出现这个错误 error: RPC failed; result=22, HTTP code = 411 fatal: The remote end hung u ...

  3. 在sharepoint2013中如使用PowerView

    在sharepoint2013中如使用PowerView 安装前提 Sql sqlserver 2012 sp1 Sharepoint2013 Sql server 2012 sp1 PowerPiv ...

  4. 更改pip源至国内镜像,显著提升下载速度(转载)

    经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具,但是由于国外官方pypi经常被墙,导致不可用,所以我们最好是将自己使用的pip源更换一下,这样就能解决被墙导致的装不上库的 ...

  5. [深入学习Web安全](5)详解MySQL注射

    [深入学习Web安全](5)详解MySQL注射 0x00 目录 0x00 目录 0x01 MySQL注射的简单介绍 0x02 对于information_schema库的研究 0x03 注射第一步—— ...

  6. 从头开始构建LINUX [LFS]

    “LINUX就是这个范”有一章专门介绍了Linux的构建,过程详细,很有意思.结合这方面的资料简要汇集一下 LFS 这个站点提供了从源代码构建一个Linux的详细步骤 书 http://archive ...

  7. Android开发学习——android存储

    Android的存储 内部存储空间RAM内存:运行内存,相当于电脑的内存ROM内存:存储内存,相当于电脑的硬盘外部存储空间 SD卡:相当于电脑的移动硬盘    * 2.2之前,sd卡路径:sdcard ...

  8. ViewPager+GridView实现横向滑动 仿大众点评

    先看演示效果: 1  ViewPager类提供了多界面切换的新效果. 新效果有如下特征: [1] 当前显示一组界面中的其中一个界面. [2] 当用户通过左右滑动界面时,当前的屏幕显示当前界面和下一个界 ...

  9. 转一篇简洁的UIView动画编程方法

    iOS  中的 UIView 动画编程其实还是很简单的,像 CSS3 一样,在给定的时间内完成状态连续性的变化呈现.比如背景色,Frame 大小,位移.翻转,特明度等. 以前我使用的编程方式都是用下面 ...

  10. Android Gradle Build Error:Some file crunching failed, see logs for details解决办法

    转载请标明出处: http://www.cnblogs.com/why168888/p/5925756.html 本文出自:[Edwin博客园] 错误日志:Error:java.lang.Runtim ...