Description
    给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的。其中
    1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi 整除 Xi+1 。
    现在要求X-因子链的最大长度和最大长度有多少条?
Input
    多组数据,每一组数据一个正整数X (X ≤ 220).
Output
    对于每组数据,输出X-因子链的最大长度和最大长度有多少条
Sample Input
    2
    3
    4
    10
    100
Sample Output
    1 1
    1 1
    2 1
    2 2
    4 6
Analysis

1.子链的长度就是分解质因数后每个质因数个数的和。为什么?如果出现一个合数,必定可以再分解使子链加长。

2.剩下的工作就是dfs,注意每一步只能选泽一种质数去分解。分解到1记一个贡献

Code

 #include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b) for(RG i=a;i<=b;++i)
#define per(i,a,b) for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
#define maxn 1048580
#define lim 1048578
using namespace std;
int n,cnt,pt,ans,ans1;
int isp[maxn],p[maxn];
int num[maxn][];
inline int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} void pre()
{
rep(i,,lim)
{
if(!isp[i]) p[++cnt]=i;
for(RG j=;j<=cnt&&p[j]*i<=lim;j++)
{
isp[i*p[j]]=;
if(!(i%p[j])) break;
}
}
} void work()
{
int res=n;
rep(i,,cnt)
{
if(!(res%p[i])){
num[++pt][]=p[i],num[pt][]=;
while(!(res%p[i])) ++num[pt][],res/=p[i],++ans1;
}
if(res==) break;
}
} void dfs(int res)
{
if(res==){ans++;return;}
for(int i=;i<=pt;i++)
{
if(num[i][])
{
num[i][]--;
dfs(res/num[i][]);
num[i][]++;
}
}
} int main()
{
pre();
while(~scanf("%d",&n))
{
pt=ans=ans1=;
work();
dfs(n);
printf("%d %d\n",ans1,ans);
}
return ;
}

X-factor Chains [POJ3421] [素数]的更多相关文章

  1. X-factor Chains(POJ3421 素数)

    X-factor Chains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6212   Accepted: 1928 D ...

  2. 杭电 2136 Largest prime factor(最大素数因子的位置)

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. UVA 11610 Reverse Prime (数论+树状数组+二分,难题)

    参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...

  4. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  5. poj3421 X-factor Chains(重复元素的全排列)

    poj3421 X-factor Chains 题意:给定正整数$x(x<=2^{20})$,求$x$的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的子序列的个数. ...

  6. HDOJ/HDU 2710 Max Factor(素数快速筛选~)

    Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 < ...

  7. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  8. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

  9. Max Factor(素数筛法)题解

    Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. 阿里 Goldeneye 四个环节落地智能监控:预测、检测、报警及定位

    阿里 Goldeneye 四个环节落地智能监控:预测.检测.报警及定位 https://www.infoq.cn/article/alibaba-goldeneye-four-links

  2. Log4Net帮助类

    工具类 using System; using System.Diagnostics; using log4net; namespace Trumgu_BI_PF.Util { public clas ...

  3. nginx做代理离线下载插件

    一.背景 被安装的服务器不能上网,无法下载插件,一个插件都还好,但是遇到插件依赖很强的需要几十个插件的依赖,这样就很麻烦. 二.环境 192.168.182.155     安装nginx     能 ...

  4. nethogs命令执行报异常的解决方法

  5. error: Microsoft Visual C++ 14.0 is required.

    缺少包的依赖!! 解决办法1. 安装 Microsoft visual c++ 14.0 https://964279924.ctfile.com/fs/1445568-239446865 或 htt ...

  6. Python题目练习(二)

    1.如何实现对python列表去重,并保持原来顺序 li = [1,2,5,3,1,6,3,8,0,3,2,4] l = [] for i in li: if i not in l: l.append ...

  7. websocket/dwebsocket 实现前后端的实时通信

    1.  用bottle框架,自己写一个服务端实现: 转载   :http://www.linuxyw.com/813.html 功能:用websocket技术,在运维工具的浏览器上实时显示远程服务器上 ...

  8. BZOJ1096 [ZJOI2007]仓库建设 动态规划 斜率优化

    原文链接http://www.cnblogs.com/zhouzhendong/p/8696410.html 题目传送门 - BZOJ1096 题意 给定两个序列$a,b,X$,现在划分$a$序列. ...

  9. springboot(@Service,@Mapper)注解失效导致无法注入service和mapper

    给我来灵感的博客:感谢:http://blog.51cto.com/xingej/2053297?utm_source=oschina-app 因为使用了注解的类在使用时是通过new出来的,导致注解注 ...

  10. JavaScript项目重构到底有多少坑要填要踩

    看到代码的那一刻我惊呆了,就一个js文件,接近2000行的代码.这个还好,比这个行数多的我见的多了,这个还吓不到我.有哪些问题,一会再说. 因为从我接手的那一刻算起,几天后就要发新版本,我只要也只能调 ...