POJ 3421

    因为题目里要求Xi | Xi+1,而Xm又限定为X,所以我们可以想到Xm-1是X除以其某个约数得到的,Xm-1也是一样。由此我们可以知道“X-factor Chains”是通过不断乘以X的约数得到的,为了长度最大,所以约数必须是素数。通过记录有哪些素因数,以及素因子的数量,我们就可以得到链的长度。
    而长度最大的链的数量则是这些数的排列数,公式为素因子个数之和的阶乘/每个素因子个数的阶乘


代码(G++):

#include <iostream>
#include <map>

using namespace std;

map<int, int> res;
map<int, int>::iterator mi;

long long fact(int n)
{
    long long v;

    if(n == 0 || n == 1) return 1;
    else{
        v = n;
        for(int i=2; i<n; i++)
        {
            v *= i;
        }
        return v;
    }
}

int main()
{
    int x, sum;
    long long ans;

    while(cin>>x)
    {
        sum = 0;
        res.clear();
        for(int i=2; i*i<=x; i++)
        {
            while(x%i == 0)
            {
                x /= i;
                ++res[i];
                ++sum;
            }
        }
        if(x != 1)
        {
            ++res[x];
            ++sum;
        }
        ans = fact(sum);
        for(mi=res.begin(); mi!=res.end(); mi++)
        {
            ans /= fact(mi->second);
        }
        cout<<sum<<' '<<ans<<endl;
    }
    return 0;
}

题目
X-factor Chains
Time Limit: 1000MS Memory Limit: 65536K

Description

Given a positive integer X, an X-factor chain of length m is a sequence of integers,

1 = X0, X1, X2, …, Xm = X

satisfying

Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.

Now we are interested in the maximum length of X-factor chains and the number of chains of such length.

Input

The input consists of several test cases. Each contains a positive integer X (X ≤ 220).

Output

For each test case, output the maximum length and the number of such X-factors chains.

Sample Input

2
3
4
10
100
Sample Output

1 1
1 1
2 1
2 2
4 6
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值