X-factor Chains (poj 3421 数学排列组合)

8 篇文章 0 订阅

Language:
X-factor Chains
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5603 Accepted: 1768

Description

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

1 = X0X1X2, …, 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

Source

POJ Monthly--2007.10.06, ailyanlu@zsu

题意:给出一个数X,现在定义1 = X0, X1, X2, …, Xm = X,其中Xi能被Xi-1整除,问满足该定义的最大m和满足最大的个数有多少。
思路:质因子们的排列组合——∏(质因子个数的阶乘)/(每个质因子的个数的阶乘)。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef long long ll;
using namespace std;

//vector<int>
//只求解整数分解的因子的幂
vector<int> prime_factor_time(int n)
{
    vector<int> res;
    for (int i=2;i*i<=n;i++)
    {
        int time=0;
        while (n%i==0)
        {
            ++time;
            n/=i;
        }
        res.push_back(time);
    }
    if (n!=1)
        res.push_back(1);
    return res;
}

//阶乘
ll factor(const int& n)
{
    ll res=1;
    for (int i=1;i<=n;i++)
        res*=i;
    return res;
}

int main()
{
    int i,j,x;
    while (~sf(x))
    {
        vector<int> num=prime_factor_time(x);
        int all=0;
        vector<int>::iterator it;
        for (it=num.begin();it!=num.end();it++)
            all+=*it;
        ll ans=factor(all);
        for (it=num.begin();it!=num.end();it++)
            ans/=factor(*it);
        pf("%d %lld\n",all,ans);
    }
    return 0;
}



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值