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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • vscode安装java运行环境_vscode eclipse对比

    vscode安装java运行环境_vscode eclipse对比vscode中怎么搭建Java开发环境?下面本篇文章给大家介绍一下VSCode配置Java开发环境的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。配置Java开发环境主要参考官方教程:https://code.visualstudio.com/docs/java/java-tutorial1.先安装JDKJDK下载地址:https://www.oracle.com/java…

  • Windows下目录和文件名长度的限制

    Windows下目录和文件名长度的限制&lt;noscripttype="text/javascript"&gt;&lt;/noscript&gt;&lt;noscripttype="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;/noscript&gt;今天,一个网友,问Windows

    2022年10月20日
  • 一文搞懂三极管开关电路,基极电阻如何选择?[通俗易懂]

    一文搞懂三极管开关电路,基极电阻如何选择?[通俗易懂]一文搞懂三极管开关电路,基极电阻如何选择?

  • mtk手机维修_mtk平台手机

    mtk手机维修_mtk平台手机默认分类2009-10-1902:21:04阅读1252评论7字号:大中小  MTK用电池不开机,用外用电源能开机的维修方法:MTK用电池不开机,用外用电源能开机的维修方法,我们可以找到VBAT也就是电触B+通电源的sas31233l213321+987+9877777777777777777777777777777777777777777777777777

    2022年10月28日
  • python机器学习库sklearn——朴素贝叶斯分类器[通俗易懂]

    python机器学习库sklearn——朴素贝叶斯分类器[通俗易懂]全栈工程师开发手册(作者:栾鹏)python数据挖掘系列教程文档贝叶斯分类器的相关的知识内容可以参考http://blog.csdn.net/luanpeng825485697/article/details/78769233在scikit-learn中,一共有3个朴素贝叶斯的分类算法类。分别是GaussianNB,MultinomialNB和Bernoulli…

  • MethodFilterInterceptor和AbstractInterceptor的比较

    MethodFilterInterceptor和AbstractInterceptor的比较在编写自定义拦截器的时候,需要继承AbstractInterceptor或者MethodFilterInterceptor,那么他们有什么不同呢首先查看MethodFilterInterceptor的源代码我们发现MethodFilterInterceptor也是继承了AbstractInterceptor的,并且MethodFilterInterceptor里面定义了两个参数,分别是excl…

发表回复

您的电子邮箱地址不会被公开。

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