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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android多媒体-人脸识别

    Android多媒体-人脸识别

    2021年11月23日
    44
  • 怎样使用灭火器正确灭火_principal和main的区别

    怎样使用灭火器正确灭火_principal和main的区别这个是翻译来的,原文地址:http://www.landley.net/writing/rootfs-howto.html怎样使用initramfs 工作过程简述在2.6kernel启动时,它把rootfs作为它的第一个文件系统挂载(注意:这里的rootfs是真名!!!不是rootfilesystem的缩写)。rootfs是一个特殊的tmpfs,这个不能被

    2022年8月11日
    5
  • python google auth totp_Google Authenticator TOTP原理详解(以Python为例)「建议收藏」

    python google auth totp_Google Authenticator TOTP原理详解(以Python为例)「建议收藏」如果有疑问,请点击此处,然后发表评论交流,作者会及时回复(也可以直接在当前文章评论)。——-谢谢您的参考,如有疑问,欢迎交流一、原理详解(图片可以点击然后放大查看)二、验证1、下载Google谷歌身份验证器。2、通过Python的qrcode和pyotp模块生成二维码。3、然后使用下载的谷歌身份验证器扫描生成的二维码如果没有谷歌服务,则选择输入秘钥,在账户明处填入name参数,在秘…

    2025年7月2日
    2
  • vim编辑器怎么退出_退出vim编辑器

    vim编辑器怎么退出_退出vim编辑器当编辑完文件,准备退出Vi返回到shell时,可以使用以下几种方法之一。  (1)在命令模式中,连按两次大写字母Z,若当前编辑的文件曾被修改过,则Vi保存该文件后退出,返回到shell;若当前编辑的文件没被修改过,则Vi直接退出,返回到shell。  (2)在末行模式下,输入命令:wVi保存当前编辑文件,但并不退出,而是继续等待用户输入命令。在使用w命令时,可以再给编辑文件起一个新的文件名。…

    2022年9月29日
    2
  • ES6新特性总结之函数和扩展运算符…

    ES6新特性总结之函数和扩展运算符…

    2021年6月13日
    123
  • 树莓派连接wifi 设置静态ip

    树莓派连接wifi 设置静态ipsudonano/etc/dhcpcd.conf,在文件结尾添加如下代码:interfacewlan0staticip_address=内网ip地址/24staticrouters=内网网关ip地址staticdomain_name_servers=114.114.114.114#自定义dnssudoreboot…

    2022年5月9日
    89

发表回复

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

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