质因数分解:

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

id=19601" class="login ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; border:1px solid rgb(211,211,211); color:blue; font-size:12px!important">Submit Status

Description

Problem D: Choose and divide

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

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

Given four natural numbers pqr, and s, compute the the result of dividing C(p,q) by C(r,s).

The Input

Input consists of a sequence of lines. Each line contains four non-negative integer numbers giving values for pqr, and s, respectively, separated by a single space. All the numbers will be smaller than 10,000 with p>=q and r>=s.

The 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

Output for Sample Input

0.12587
505606.46055
1.28223
0.48996
2.00000
3.99960

Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples

Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 6. Mathematical Concepts and Methods

Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Combinatorics :: 

option=com_onlinejudge&Itemid=8&category=405" style="color:blue; text-decoration:none">Binomial
Coefficients


Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Combinatorics :: Binomial
Coefficients




Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 5. Mathematics :: Combinatorics

Root :: Prominent Problemsetters :: Gordon V. Cormack

Submit Status

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std; const int maxn=10010; int p,q,r,s; int prime[maxn],pn;
long long int fnum[maxn],pnum[maxn];
bool vis[maxn]; void pre_init()
{
memset(vis,true,sizeof(vis));
for(int i=2; i<maxn; i++)
{
if(i%2==0&&i!=2) continue;
if(vis[i]==true)
{
prime[pn++]=i;
for(int j=2*i; j<maxn; j+=i)
{
vis[j]=false;
}
}
}
} void fenjie_x(int x,long long int* arr)
{
for(int i=0; i<pn&&x!=1; i++)
{
while(x%prime[i]==0)
{
arr[i]++;
x/=prime[i];
}
}
} void fenjie(int x,long long int* arr)
{
for(int i=2; i<=x; i++)
fenjie_x(i,arr);
} void jianshao()
{
for(int i=0; i<pn; i++)
{
long long int Min=min(fnum[i],pnum[i]);
fnum[i]-=Min;
pnum[i]-=Min;
}
} int main()
{
pre_init();
while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF)
{
memset(pnum,0,sizeof(pnum));
memset(fnum,0,sizeof(fnum));
fenjie(p,pnum);fenjie(s,pnum);fenjie(r-s,pnum);
fenjie(q,fnum);fenjie(r,fnum);fenjie(p-q,fnum);
jianshao();
double ans=1.;
for(int i=0; i<pn; i++)
{
while(pnum[i]--)
{
ans*=1.*prime[i];
}
while(fnum[i]--)
{
ans/=1.*prime[i];
}
}
printf("%.5lf\n",ans);
}
return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

UVA10375 Choose and divide 质因数分解的更多相关文章

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

  2. uva10375 Choose and divide

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

  3. 关于Miller-Rabin与Pollard-Rho算法的理解(素性测试与质因数分解)

    前置 费马小定理(即若P为质数,则\(A^P\equiv A \pmod{P}\)). 欧几里得算法(GCD). 快速幂,龟速乘. 素性测试 引入 素性测试是OI中一个十分重要的事,在数学毒瘤题中有着 ...

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

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

  5. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  6. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

  7. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

  8. 整数分解 && 质因数分解

    输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...

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

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

随机推荐

  1. FZU2082

    树链剖分后要处理的是边的权值,而不是点的权值,但是只要边权下放到点,就可以了 如图 但是问题是,求图4->5路径的权值之和, 那么就会把点3给算进去 那么就要减去, 或者干脆不加进去 有两种方法 ...

  2. ecshop首页调用某分类下的商品|assign_cat_goods()

    ecshop首页调用分类下的商品其实很简单,也有模板设置那里可以设置,不过那个只可以用cat_goods.lib,不方便,所以我想看看怎么能简单的实现ecshop首页调用分类下的商品 只需要在inde ...

  3. 王立平--Program Files (x86)

    window7根据系统.program files(x86) 它是应用程序目录,在64下位系统.为了更好的相容性32位程序,在一些安装32位程序(请注意,有些节目自己是32位),将默认被安装progr ...

  4. Cocos移植Android-Android.mk编译后的文件

    在以前的博客,我们使用的中年cocos工具C和C++源代码可以编译. 其实cocos工具读取<游戏project文件夹>\proj.android\jni\夹Android.mk文件,.A ...

  5. ORA-00600 [kollasg:client-side tmp lob]

    今天在查看一个库的日志时,发现被ORA-00600 [kollasg:client-side tmp lob] 错误刷屏了. 发生该错误的原因是由于应用那边lob的问题.lob没有被初始化,建议使用E ...

  6. 在小发现SQL字符串比较是不是他们的大写和小写敏感

    声明:select  petName from dbo.T_pet order by petName desc 成绩:    petName    An admin A的ascii码小于a,按理说应该 ...

  7. iOS 8 新特性

    这篇文章会介绍iOS8开发相关的主要特性. App 插件 通过支持插件,iOS8让我们可以系统指定的区域进行扩展,也就是为用户的特定需求提供自定义的方法.例如:可以通过App插件帮助用户分享他们的内容 ...

  8. 皮尔逊相似度计算的例子(R语言)

    编译最近的协同过滤算法皮尔逊相似度计算.下顺便研究R简单使用的语言.概率统计知识. 一.概率论和统计学概念复习 1)期望值(Expected Value) 由于这里每一个数都是等概率的.所以就当做是数 ...

  9. 【rman,1】经典案例增量备份

    一.备份策略: 1.星期天晚上      -level 0 backup performed(全备份) 2.星期一晚上      -level 2 backup performed 3.星期二晚上   ...

  10. Web API Test Client 1.2.0

    使用方法 1 安装 matthewcv.WebApiTestClient 到你的Web API 项目 PM> Install-Package matthewcv.WebApiTestClient ...