zoukankan      html  css  js  c++  java
  • POJ3421——X-factor Chain(质因数分解)

    传送门

    考虑到序列中每一个数都必须是前一个的倍数

    所以每个质因子数必然会且只会被在一个位置乘上一次

    所以序列的最长就是质因子的个数

    而对于方案数

    考虑到对于第ii个数

    那么就有lenilen-i个位置还可以放

    那么方案数就要乘上lenilen-i

    那么所以算下来就是len!len!

    所以方案数就是len!len!

    
    #include<bits/stdc++.h>
    using namespace std;
    inline int read(){
        char ch=getchar();
        int res=0;
        while(!isdigit(ch))ch=getchar();
        while(isdigit(ch)) res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
        return res;
    }
    #define ll  long long
    ll fac[25];
    int prime[2000000],cnt;
    bool vis[2000005];
    int x;
    inline void init(){
        fac[0]=fac[1]=1;
        for(int i=2;i<=22;i++){
            fac[i]=fac[i-1]*i;
        }
    }
    inline void getprime(){
        for(int i=2;i<=2000000;i++){
            if(!vis[i]){
                prime[++cnt]=i;
                for(int j=i;j<=2000000;j+=i){
                    vis[j]=true;
                }
            }
        }
    }
    int main(){
        init();
        getprime();
        while(scanf("%d",&x)!=EOF){
            ll tot=0,ans=1;
            for(int i=2;i*i<=x;i++){
                int num=0;
                while(x%i==0){
                    num++;x/=i;
                }
                tot+=num;ans*=fac[num];
            }
            if(x>1)tot++;
            cout<<tot<<" ";
            cout<<fac[tot]/ans<<'
    ';
        }
    }
    
  • 相关阅读:
    python3 基础数据类型之列表及其操作方法
    python3 逻辑运算符
    python3 内置函数
    python3 装饰器
    python3 变量作用域
    python3 参数以及函数的传参
    python3 函数基础
    洛谷P3379倍增LCA
    洛谷P3375KMP字符串匹配
    洛谷P2613有理数取余
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/10366449.html
Copyright © 2011-2022 走看看