1692: X-factor Chains

题目描述

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.

输入

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

输出

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

 

样例输入 

2
3
4
10
100

样例输出 

1 1
1 1
2 1
2 2
4 6

翻译

给定正整数 X,长度为 m 的 X 因子链是整数序列,1 = X0, X1, X2, …, Xm = X 满足 Xi < Xi+1 且 Xi |Xi+1 其中 a |b 表示 a 完全分为 b。现在我们感兴趣的是 X 因子链的最大长度以及该长度的链的数量。输入 输入由多个测试用例组成。每个都包含一个正整数 X (X ≤ 220)。输出 对于每个测试用例,输出此类 X 因子链的最大长度和数量。

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <utility>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>

using namespace std;
typedef long long LL;
const int INF_INT=0x3f3f3f3f;
const LL INF_LL=0x3f3f3f3f3f3f3f3f;

LL factorial[21];
bool is_prime[10000];
int prime[10000];
int cnt;
int num[10000];
int k;

void pre()
{
    factorial[0]=factorial[1]=1;
    for(int i=2;i<=20;i++) factorial[i]=factorial[i-1]*i;
    for(int i=2;i<=9000;i++) is_prime[i]=true;
    for(int i=2;i<=9000;i++)
    {
        if(is_prime[i])
        {
            prime[cnt++]=i;
            for(int j=(i<<1);j<=9000;j+=i) is_prime[j]=false;
        }
    }
}

void prime_factor(int x)
{
    k=0,num[k]=0;
    LL sum=0;
    for(int i=0;i<cnt;i++)
    {
        while(!(x%prime[i])) x/=prime[i],num[k]++;
        sum+=num[k];
        k++,num[k]=0;
    }
    if(x!=1) sum++;
    printf("%lld ",sum);
    sum=factorial[sum];
    for(int i=0;i<k;i++) sum/=factorial[num[i]];
    printf("%lld\n",sum);
}

int main()
{
    pre();
    int x;
    while(~scanf("%d",&x)) prime_factor(x);
    return 0;
}

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值