zoukankan      html  css  js  c++  java
  • 普及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),懵逼传送门

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

    完结撒花!!!

  • 相关阅读:
    PgSQL定时备份
    如何从源码包安装软件?
    PostgreSQL PointInTime Recovery (Incremental Backup)
    Better PostgreSQL backups with WAL archiving
    安装GTK全攻略
    WEB前端开发规范文档
    Linux开机自动启动脚本方法
    安装编译postgresql与pgagent的相关操作
    PostgreSQL: 如何查询表的创建时间?
    什么是编程
  • 原文地址:https://www.cnblogs.com/YYCether666/p/11372800.html
Copyright © 2011-2022 走看看