X-factor Chains
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7733   Accepted: 2447

Description

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.

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

大致题意:构造一个序列,使得ai整除ai+1,a0 = 1,an = x,现在给定x,求这样的序列最长的长度是多少?有多少个?
分析:将x分解质因数.从第i个数变成第i-1个数就是去掉一个质因子,那么把x的质因子的次数加上,这就是第一问的答案.第二问实际上就是要求排列数,相同的数在不同的位置只能算一次.那么利用可重复的排列数公式计算即可.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
ll n,ans,jie[],sum,yinzi[],tot,mul; int main()
{
jie[] = ;
for (int i = ; i <= ; i++)
jie[i] = jie[i - ] * i;
while (scanf("%lld",&n) != EOF)
{
tot = ans = sum = ;
mul = ;
memset(yinzi,,sizeof(yinzi));
for (ll i = ; i * i <= n; i++)
{
if (n % i == )
{
++tot;
while (n % i == )
{
n /= i;
yinzi[tot]++;
sum++;
}
}
}
if (n > )
{
++tot;
++sum;
yinzi[tot]++;
}
printf("%lld ",sum);
ans = jie[sum];
for (int i = ; i <= tot; i++)
mul *= jie[yinzi[i]];
ans /= mul;
printf("%lld\n",ans);
} return ;
}

poj3421 X-factor Chains的更多相关文章

  1. POJ3421:X-factor Chains——题解

    http://poj.org/problem?id=3421 题目大意:一个数列,起始为1,终止为一给定数X,满足Xi < Xi+1 并且Xi | Xi+1. 求出数列最大长度和该长度下的情况数 ...

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

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

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

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

  4. X-factor Chains(POJ3421 素数)

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

  5. X-factor Chains [POJ3421] [素数]

    Description    给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中    1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...

  6. poj3421 X-factor Chains——分解质因数

    题目:http://poj.org/problem?id=3421 好久没有独立A题了...做点水题还是有助于提升自信心的: 这题就是把 x 质因数分解,质因数指数的和 sum 就是最长的长度,因为每 ...

  7. 代码的坏味道(20)——过度耦合的消息链(Message Chains)

    坏味道--过度耦合的消息链(Message Chains) 特征 消息链的形式类似于:obj.getA().getB().getC(). 问题原因 如果你看到用户向一个对象请求另一个对象,然后再向后者 ...

  8. 【转载】latch: cache buffers chains

    本文转自惜分飞的博客,博客原文地址:www.xifenfei.com/1109.html,支持原创,分享知识! 当一个数据块读入sga区,相应的buffer header会被放置到hash列表上,我们 ...

  9. Leetcode 254. Factor Combinations

    Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...

随机推荐

  1. MySQL高性能优化实战总结

    1.1 前言 MySQL对于很多Linux从业者而言,是一个非常棘手的问题,多数情况都是因为对数据库出现问题的情况和处理思路不清晰.在进行MySQL的优化之前必须要了解的就是MySQL的查询过程,很多 ...

  2. linux下各文件夹的结构说明及用途介绍(转载)

    详细介绍文档 转载文章路径 /bin:二进制可执行命令. /dev:设备特殊文件. /etc:系统管理和配置文件. /etc/rc.d:启动的配 置文件和脚本. /home:用户主目录的基点,比如用户 ...

  3. Literature Books

    Lean In (Sheryl Sandberg) Option B (Sheryl Sandberg) Ready Player One

  4. 如何在Ubuntu 18.04上安装Go

    如何在Ubuntu 18.04上安装Go 谢鸢发表于云计算教程系列订阅98 介绍 课程准备 第1步 - 安装Go 第2步 - 设置Go路径 第3步 - 测试您的安装 结论 介绍 Go是Google开发 ...

  5. PSP阶段和WBS

    项目:PSP Daily 详情请见项目功能说明书 PSP2.1 Personal Software Process Stages 预估耗时长 Planning 计划   · Estimate · 开发 ...

  6. 关于双系统下Ubuntu不能访问Windows中某个盘的问题

    1.问题描述   在Ubuntu系统下访问Windows系统中磁盘时出现无法访问的情况,具体如下显示:   该问题为磁盘挂载错误,需要进行修复. 2.解决办法   (1)打开终端:如果没有安装ntfs ...

  7. Python入门:认识变量和字符串

    几个月前,我开始学习个人形象管理,从发型.妆容.服饰到仪表仪态,都开始做全新改造,在塑造个人风格时,最基础的是先了解自己属于哪种风格,然后找到参考对象去模仿,可以是自己欣赏的人.明星或模特等,直至最后 ...

  8. 新浪 ip 地址库

    API地址:http://int.dpool.sina.com.cn/iplookup/iplookup.php 帮助 1 2 3 4 5 6 7 8 function get_location($i ...

  9. node进程捕捉错误

    var childProcess = require('child_process'); var commitMessage = (function() { var spawn = childProc ...

  10. Spring Cloud 架构 五大神兽的功能

    什么是微服务 微服务的概念源于2014年3月Martin Fowler所写的一篇文章“Microservices”. 微服务架构是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相协调 ...