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


相关推荐

  • 关于Raid0,Raid1,Raid5,Raid10的总结

    关于Raid0,Raid1,Raid5,Raid10的总结RAID0定义:RAID0又称为Stripe或Striping,它代表了所有RAID级别中最高的存储性能。RAID0提高存储性能的原理是把连续的数据分散到多个磁盘上存取,这样,系统有数据请求就

    2022年7月1日
    21
  • SQL Server 触发器[通俗易懂]

    SQL Server 触发器[通俗易懂]SQLServer触发器

    2022年6月20日
    34
  • 树莓派连接wifi教程[通俗易懂]

    树莓派连接wifi教程[通俗易懂]第一种方法:如果你已经连接了VNC图形界面,就像手机电脑一样点击wifi的图标找到你的wifi输入密码就行第二种方法:如果登录了putty1.输入sudonano/etc/wpa_supplicant/wpa_supplicant.conf2.在尾部添加network={ssid=""psk=""}引号内容SSID是你的无线名称PSK是你的无线密码无线名称不能是中…

    2022年4月28日
    356
  • 浏览器对url长度限制_url过长怎么解决

    浏览器对url长度限制_url过长怎么解决HTTP1.0的格式request(HTTP请求消息)结构:一个请求行.部分消息头,以及实体内容,其中的一些消息内容都是可选择的.消息头和实体内容之间要用空行分开.GET/index.htmlHTTP/1.1//请求头,下面都是消息头.Accept:*/*Accept-Languang:en-usConnection:keep-aliveHost:localhostReferer:HTTP…

    2022年8月24日
    55
  • pycharmhtml插件_pycharm使用技巧

    pycharmhtml插件_pycharm使用技巧“阅读本文大概需要3分钟。”写Python,很多朋友都用的PyCharm,包括我在内。但其实大部分情况下我们用到的功能可能仅仅占PyCharm功能的一小半都不到。本文推荐…

    2022年8月28日
    3
  • matlab香农编码「建议收藏」

    matlab香农编码「建议收藏」1、读入图像使用imread()函数读入图像,由于m文件和图像放在同一目录下,故采用相对路径。img=imread(‘1.png’);2、统计灰度值使用imhist()函数,对图像的灰度值在[0,255]上做统计,统计每个灰度值出现的概率size()函数用来计算图像的大小。num=imhist(img);[m,n]=size(img);px=num/(m*n)…

    2022年9月11日
    3

发表回复

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

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