普及C组第四题(8.18)

1574. 【提高】X-因子链 
(File IO): input:factor.in output:factor.out

时间限制: 1000 ms  空间限制: 131072 KB

题目描述

给一个正整数X,一个长度为m的X-因子链是指这样一个序列:X0=1,X1,X2,。。。,Xm=X满足:Xi<Xi+1同时Xi |Xi+1(Xi+1能被Xi整除)

 

要求X-因子链的最大长度Len和长度为Len的X-因子链的数量。

 

输入

     一个正整数X(X <231)

输出

     一行,两个整数,分别表示最大长度和该长度链的种数。

 

样例输入

100

样例输出

4 6

 

数据范围限制

思考:

一看题目,一脸懵逼;再看范围,两脸懵逼;再探题目,三脸懵逼;

(ノ=Д=)ノ┻━┻

懵逼树上懵逼果,懵逼树下你和我)进入正题:

这道题就暴力枚举好了,只要知道因子链的数量相当于不重复的全排列就行了(感觉自己写的好水啊

CODE:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,tot=0;
long long ans=0;
int a[31];
void chazhao(int x)
{
    for(int i=2;i<=x;i++)
    {
        if((x%i)==0)
        {
            a[tot]=i;
            tot++;
            return chazhao(x/i);
        }
    }
}
int main()
{
    freopen("factor.in","r",stdin);
    freopen("factor.out","w",stdout);
    cin>>n;
    chazhao(n);
    do
    {
        ans++;
    }
    while (next_permutation(a,a+tot));
    cout<<tot<<" "<<ans;
    return 0;
}

next_permutation(a,a+tot)

这东西我只是偷懒写的别在意;

完结撒花!!!

猜你喜欢

转载自www.cnblogs.com/YYCether666/p/11372800.html