质因数分解:

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. Flipping Game(枚举)

    Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. poj1655 Balancing Act 找树的重心

    http://poj.org/problem? id=1655 Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. eclipse重构详解(转)

    重构是对软件内部结构的一种调整,目的是在不改变软件行为的前提下,提高其可理解性,降低其修改成本.开发人员可以使用一系列重构准则,在不改变软件行为的前提下,调整软件的结构. 有很多种原因,开发人员应该重 ...

  4. Android学习之 AChartEngine 图表绘制

    Android 开源图表绘制工具AChartEngine地址:http://code.google.com/p/achartengine/ AChartEngine Android实现图表绘制和展示( ...

  5. PB数据库相关

    ---------------------------------------------------------------- 数据库画板: 一张表定义了主键或者唯一索引,则能够在Results视窗 ...

  6. C++ 中的比較函数

    在敲代码的时候,排序是一种和经常使用的算法.在排序中.比較又是当中最经常使用的操作.这里,我们来分析一下C++中的比較问题. 当中,基本数据类型int. float.string等已经提供了默认的比較 ...

  7. 阿赫亚web安全JSON

    前言 JSON(JavaScript Object Notation),可以说,这一事实,浏览器,server数据交换标准.的格式如XML,或者其他自己定义的格式会越来越少. 为什么JSON这么流行? ...

  8. WebPack实例与前端性能优化

    [前端构建]WebPack实例与前端性能优化   计划把微信的文章也搬一份上来. 这篇主要介绍一下我在玩Webpack过程中的心得.通过实例介绍WebPack的安装,插件使用及加载策略.感受构建工具给 ...

  9. W5500 keep-alive的用途及使用

    大家是否遇到过这种问题,W5500作为server已经建立连接,突然网线掉了,然后再去连接W5500.就连不上了. 为什么?以下对这个问题进行解释说明,并提出解决的方法. 图1中的上位机程序作为cli ...

  10. Blend4精选案例图解教程(一):丰富的形状(Shape)资源

    原文:Blend4精选案例图解教程(一):丰富的形状(Shape)资源 Blend4资源面板中内置了丰富的形状素材,为我们在构建程序时提供极大的方便.系统默认内置18种常用形状,通过其属性设置可以自定 ...