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)
上一篇 2022年1月9日 下午5:00
下一篇 2022年1月9日 下午5:00


相关推荐

  • 【STM32】HAL库 STM32CubeMX教程九—ADC[通俗易懂]

    【STM32】HAL库 STM32CubeMX教程九—ADC[通俗易懂]前言:本系列教程将对应外设原理,HAL库与STM32CubeMX结合在一起讲解,使您可以更快速的学会各个模块的使用所用工具:1、芯片:STM32F407ZET6/STM32F103ZET62、STM32CubeMx软件3、IDE:MDK-Keil软件4、STM32F1xx/STM32F4xxHAL库知识概括:通过本篇博客您将学到:ACD工作原理STM32CubeMX创建…

    2022年10月21日
    9
  • 操作系统概念第七章部分作业题答案

    操作系统概念第七章部分作业题答案题目一:考虑下图所示的交通死锁的情况:(1)请说明这个实例中死锁的4个必要条件(2)请设计一条简单的规则来避免产生死锁解答:(1):死锁的四个必要条件是:①互斥:至少一个资源非共享,即一次只能有一个进程使用②占有并等待:一个进程至少占有一个资源,并等待另一个资源,而该资源被其他进程所占有③非抢占:资源非抢占,只有当前进程完成任务才能被释放④循环等待:有一组等待进城P0…P…

    2022年7月14日
    18
  • Purify命令大全

    Purify命令大全1 nbsp nbsp nbsp nbsp nbsp ABR arrayboundsr 数组越界读 1 1 nbsp nbsp nbsp nbsp nbsp 介绍 AnABRmessage AnABRmessage

    2026年3月18日
    2
  • gridview的属性_grid css

    gridview的属性_grid css正在做一个项目,其中用到了Gridview控件,内容如下即每行里又包括两小行,这个功能可以用两个嵌套的gridview实现,第二个要实现的是每个大行之间用实现相隔,每个小行之间用虚线网上很多资料都是关于Gridview的,但是关于样式的就不多后来发现可以在后台程序中动态改变CELL的式样protectedvoidGridView2_RowDataBound(obj

    2025年12月1日
    13
  • 用Trae IDE+GLM4.6 API 搭了个小红书文案生成器,新手也能秒出爆款!附保姆级教程

    用Trae IDE+GLM4.6 API 搭了个小红书文案生成器,新手也能秒出爆款!附保姆级教程

    2026年3月12日
    4
  • apap图像全景拼接

    apap图像全景拼接文章目录基本原理图像配准关于最小割关于最大流apap的实现流程代码实现实验场景场景一场景二遇到的问题基本原理图像配准图像配准(apap)是将两张场景相关的图像进行映射,寻找其中的关系,多用在医学图像配准、图像拼接、不同摄像机的几何标定等方面,其研究也较为成熟。OpenCv中的stitching类就是使用了2007年的一篇论文(Automaticpanoramicimagestitchi…

    2026年2月18日
    8

发表回复

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

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