zoukankan      html  css  js  c++  java
  • UVA10375 Choose and divide 质因数分解


    质因数分解:


    Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

     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 pqr, 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 pqr, 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 3: The New Lower Bound of Programming Contests (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


    #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
    ",ans);
        }
        return 0;
    }
    




    版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

  • 相关阅读:
    双主双写、只备份某些表且要在建表ID自增
    我的系统资源呢?php-fpm你知道吗?
    apache常用的两种工作模式 prefork和worker
    Binlog的三种模式
    Tomcat
    JVM初识、调优
    httpclient 3.1跳过https请求SSL的验证
    POM报错Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from
    eclipse快捷键,移动和复制一段代码
    org.codehaus.jettison.json.JSONObject使用方法
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4749695.html
Copyright © 2011-2022 走看看