质因数分解:

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. OUI-67076 : OracleHomeInventory was not able to create a lock file&quot; in Unix

    Symptoms The command "opatch lsinventory" reports the error: OUI-67076:OracleHomeInventory ...

  2. 经常使用的正則表達式归纳—JavaScript正則表達式

    来源:http://www.ido321.com/856.html 1.正则优先级 首先看一下正則表達式的优先级,下表从最高优先级到最低优先级列出各种正則表達式操作符的优先权顺序: 2.经常使用的正則 ...

  3. u-boot: Error: Can&#39;t overwrite &quot;ethaddr&quot;

    When try to execute following command, It reports error as following: --->8--- U-Boot> setenv ...

  4. java 线程 新类库中的构件 countDownLatch 使用

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbmdydWkxOTg4/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  5. webservice一片:其中在外线呼叫数据,查看返回数据

    经Android数据被访问,返回的数据(json格公式,object数据类型:strJson) 业务需求:经webservice调用外部暴露数据并返回json数据序列化.阅读到数据库表:[SQ_Eve ...

  6. net Mvc模块化开发

    Asp.net Mvc模块化开发之“部分版本部分模块更新(上线)” 项目开发从来就不是一个简单的问题.更难的问题是维护其他人开发的项目,并且要修改bug.如果原系统有重大问题还需要重构. 怎么重构系统 ...

  7. Access之C#连接Access

    原文:Access之C#连接Access 如果是个人用的小程序的话.一般都推荐用Sqlite和Access 使用SQlite数据库需要安装SQLite驱动,详情:SQLite之C#连接SQLite 同 ...

  8. erlang shell表格数据对齐

    近期在erlang shell做一些測试,为了让測试结果数据显得更直观,想对齐须要打印的数据,做成像表格一样的效果. 開始的想法是在数据中插入tab. 当然,erlang也有对tab的支持,但实际效果 ...

  9. [Windows Phone] 如何撰写连接 Wifi、蓝芽、网路、飞航模式的网路设定功能

    原文:[Windows Phone] 如何撰写连接 Wifi.蓝芽.网路.飞航模式的网路设定功能 前言 为了可以使自己的 APP 具备操作网路的功能,在本文分享研究心得,包含在 Windows Pho ...

  10. android集成apk对一些问题经常遇到系统

    1.集成APK必须确认是否release版本号,否则会导致CTS测试失败. 途径:反编译apk,视图manifest.xml文件,看<application>在那里debug属性:andr ...