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


相关推荐

  • 跳表介绍和实现_真人二段跳教学

    跳表介绍和实现_真人二段跳教学想慢慢的给大家自然的引入跳表。想想,我们1)在有序数列里搜索一个数2)或者把一个数插入到正确的位置都怎么做?很简单吧对于第一个操作,我们可以一个一个比较,在数组中我们可以二分,这样比链表快对于第二个操作,二分也没什么用,因为找到位置还要在数组中一个一个挪位置,时间复杂度依旧是o(n)。那我们怎么发明一个查找插入都比较快的结构呢?可以打…

    2022年10月31日
  • 刀塔霸业未能连接到服务器,刀塔霸业进不去怎么解决 进不去解决方法详解[多图]…

    刀塔霸业未能连接到服务器,刀塔霸业进不去怎么解决 进不去解决方法详解[多图]…刀塔霸业有很多玩家爱下好游戏之后却进不去,不知道什么原因,下面安族小编带大家来看一下进不去解决方法详解,相信对大家会有帮助。刀塔霸业玩不了解决办法1、游戏需要的手机配置iOS系统需要至少1.5内存,因此iPhone6/6PLUS无法运行,需要更新的机型才可以安卓版的话,目前由于安卓适配原因,运行效果都比较差,骁龙835处理器以下的用户可能运行情况不好,这个可以等待后续官方的优化。2、已发生错误I…

    2022年5月17日
  • Dubbo负载均衡策略及自行扩展负载均衡策略

    Dubbo负载均衡策略及自行扩展负载均衡策略负载均衡在集群负载均衡时,Dubbo提供了多种均衡策略,缺省为random随机调用。可以自行扩展负载均衡策略,参见:负载均衡扩展负载均衡策略RandomLoadBalance随机,按权重设置随机概率。在一个截面上碰撞的概率高,但调用量越大分布越均匀,而且按概率使用权重后也比较均匀,有利于动态调整提供者权重。RoundRobinLoadBalance轮循,按公约后的权重设置轮循比率。存在…

    2022年7月11日
  • linux 文件重命名_手机文件重命名

    linux 文件重命名_手机文件重命名没有专门的重命名命令用mvab就可以重命名了=========================================mv:move移动文件(延伸功能:重命名,linux系统没有专门的重命名命令)基本格式:移动文件:mv文件名移动目的地文件名重命名文件:mv文件名修改后的文件名…

    2022年9月10日
  • 西门子PLC学习笔记二-(工作记录)

    西门子PLC学习笔记二-(工作记录)

    2021年12月5日
  • Android面试题之Service

    Android面试题之Service1.service是否在mainthread中执行,service里面是否能执行耗时的操作?默认情况,如果没有service所运行的进程,Service和Activity是运行在当前app所在进程中的mainthread里面service里面不能执行耗时的操作(网络请求,拷贝数据库,大文件)特殊情况,可以在清单文件中配置service所在的进程,让service在另外的进程中执行。

    2022年5月21日

发表回复

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

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