zoukankan      html  css  js  c++  java
  • POJ 3421 X-factor Chains

    根据唯一分解定理:

    [N=P_1^{alpha_1}P_2^{alpha_2}cdots P_n^{alpha_n} ]

    要求(N)的大于 (1) 的因子组成的满足任意前一项都能整除后一项的严格递增序列,其中的某一满足条件的序列如下:

    [P_1,P_1^2, cdots ,P_1^{alpha_1},P_1^{alpha_1}P_2,cdots,P_1^{alpha_1}P_2^{alpha_2},cdots,P_1^{alpha_1}P_2^{alpha_2}cdots P_n^{alpha_n} ]

    可通过改变每次乘的质因子,进而得到不同的序列。

    其中,长度为:(alpha_1+alpha_2+cdots+alpha_n),根据多重集的排列数,满足条件的总个数为:(frac{(alpha_1+alpha_2+cdots+alpha_n)!}{alpha_1!alpha_2!cdots alpha_n!})

    unordered_map<int,int> fac;
    int n;
    
    void divide(int n)
    {
        for(int i=2;i*i<=n;i++)
            if(n % i == 0)
            {
                while(n % i == 0)
                {
                    fac[i]++;
                    n/=i;
                }
            }
        if(n > 1) fac[n]++;
    }
    
    LL fact(int n)
    {
        LL res=1;
        for(int i=1;i<=n;i++) res=res*i;
        return res;
    }
    
    int main()
    {
        while(cin>>n)
        {
            fac.clear();
            divide(n);
    
            int up=0;
            LL down=1;
            for(auto t:fac)
            {
                up+=t.se;
                down=down*fact(t.se);
            }
            cout<<up<<' '<<fact(up)/down<<endl;
        }
        //system("pause");
        return 0;
    }
    
    
  • 相关阅读:
    翻转数组
    C语言之指针
    C语言之结构体
    C语言之函数
    数据结构之typedef
    数据结构之树
    数据结构之链表
    数据结构之队列
    数据结构之数组
    ssh远程连接控制 linux 口令、密钥连接
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14614173.html
Copyright © 2011-2022 走看看