UVA10375 Choose and divide 质因数分解

UVA10375 Choose and divide 质因数分解

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

质因数分解:


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

Submit Status

Description

Download as PDF

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 
p
q
r, 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 
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.

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 :: 
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

 Status

UVA10375 Choose and divide 质因数分解

#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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117175.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • html空格代码是什么?html中空格怎么打「建议收藏」

    html空格代码是什么?html中空格怎么打「建议收藏」html空格代码是什么?html中空格怎么打?对于刚刚入门的新手来说可能比较陌生,下面我们来总结一下html空格代码。打造全网web前端全栈资料库(总目录)看完学的更快,掌握的更加牢固,你值得拥有(持续更新)一:html空格代码是什么说到html空格代码很多人都会想到&nbsp,其实这也是表示html空格的一种方法,当我们输入十个&nbsp就表示有十个空格,然而在现实中,也有很多人认为html空格就是在html中输入几个空格键,如果是单纯的输入空格键,也是可以起到空格的效果.

    2022年9月22日
    0
  • IDEA2021.5.1-2038激活码激活【在线注册码/序列号/破解码】「建议收藏」

    IDEA2021.5.1-2038激活码激活【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    50
  • 风控模型及特征的上线部署方法

    风控模型及特征的上线部署方法序言:作为年后的首篇实操干货文章,番茄风控一如既往向业内小伙伴输出相关的干货文章。有实操能落地,有数据可撸码,继续将会是番茄风控提供给各位小伙伴的业内标配内容。近期,我们花费了时间容整理了目前业内各位小伙伴关心的内容,本次文章是其中一个问题就是模型跟规则在现有的风控系统内是如何规范上线的,基于此,我们给大家带来了这样的一篇内容。本次文章内容翔实,章节就有四大部分,内容绝对干货满满,实操性十足。老规矩,文章中提及的更详情(数据集+代码内容)可以直接到知识课堂中下载学习。本文有理论,有方法,有实操,还有数

    2022年5月4日
    70
  • Oracle连接查询,彻底搞懂外连接(左外连接&右外连接)

    Oracle连接查询,彻底搞懂外连接(左外连接&右外连接)Oracle连接查询有3种:交叉连接、内连接、外连接。交叉连接结果是其他连接结果的超集,外连接结果是内连接结果的超集。接下的例子以departments_v、employees_v两个视图数据为例(4条部门数据,9条人员数据)1.交叉连接:又称笛卡尔积连接,是两个或多个表间的无条件连接,因此它会将表1的每一条数据与表2的每一条数据连接,因此结果会有4*9=36条数据

    2022年5月5日
    281
  • golang2021激活码【注册码】

    golang2021激活码【注册码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    78
  • RHCSA_rhce考试题库

    RHCSA_rhce考试题库1、SElinux必须运行在Enforcing模式下。1、SElinux必须运行在Enforcing模式下。2、配置YUM源,使用地址http://content.example.com/rhel

    2022年8月6日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号