poj3421 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
#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的更多相关文章
- POJ3421:X-factor Chains——题解
http://poj.org/problem?id=3421 题目大意:一个数列,起始为1,终止为一给定数X,满足Xi < Xi+1 并且Xi | Xi+1. 求出数列最大长度和该长度下的情况数 ...
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- poj3421 X-factor Chains(重复元素的全排列)
poj3421 X-factor Chains 题意:给定正整数$x(x<=2^{20})$,求$x$的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的子序列的个数. ...
- X-factor Chains(POJ3421 素数)
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6212 Accepted: 1928 D ...
- X-factor Chains [POJ3421] [素数]
Description 给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中 1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...
- poj3421 X-factor Chains——分解质因数
题目:http://poj.org/problem?id=3421 好久没有独立A题了...做点水题还是有助于提升自信心的: 这题就是把 x 质因数分解,质因数指数的和 sum 就是最长的长度,因为每 ...
- 代码的坏味道(20)——过度耦合的消息链(Message Chains)
坏味道--过度耦合的消息链(Message Chains) 特征 消息链的形式类似于:obj.getA().getB().getC(). 问题原因 如果你看到用户向一个对象请求另一个对象,然后再向后者 ...
- 【转载】latch: cache buffers chains
本文转自惜分飞的博客,博客原文地址:www.xifenfei.com/1109.html,支持原创,分享知识! 当一个数据块读入sga区,相应的buffer header会被放置到hash列表上,我们 ...
- 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 ...
随机推荐
- MySQL高性能优化实战总结
1.1 前言 MySQL对于很多Linux从业者而言,是一个非常棘手的问题,多数情况都是因为对数据库出现问题的情况和处理思路不清晰.在进行MySQL的优化之前必须要了解的就是MySQL的查询过程,很多 ...
- linux下各文件夹的结构说明及用途介绍(转载)
详细介绍文档 转载文章路径 /bin:二进制可执行命令. /dev:设备特殊文件. /etc:系统管理和配置文件. /etc/rc.d:启动的配 置文件和脚本. /home:用户主目录的基点,比如用户 ...
- Literature Books
Lean In (Sheryl Sandberg) Option B (Sheryl Sandberg) Ready Player One
- 如何在Ubuntu 18.04上安装Go
如何在Ubuntu 18.04上安装Go 谢鸢发表于云计算教程系列订阅98 介绍 课程准备 第1步 - 安装Go 第2步 - 设置Go路径 第3步 - 测试您的安装 结论 介绍 Go是Google开发 ...
- PSP阶段和WBS
项目:PSP Daily 详情请见项目功能说明书 PSP2.1 Personal Software Process Stages 预估耗时长 Planning 计划 · Estimate · 开发 ...
- 关于双系统下Ubuntu不能访问Windows中某个盘的问题
1.问题描述 在Ubuntu系统下访问Windows系统中磁盘时出现无法访问的情况,具体如下显示: 该问题为磁盘挂载错误,需要进行修复. 2.解决办法 (1)打开终端:如果没有安装ntfs ...
- Python入门:认识变量和字符串
几个月前,我开始学习个人形象管理,从发型.妆容.服饰到仪表仪态,都开始做全新改造,在塑造个人风格时,最基础的是先了解自己属于哪种风格,然后找到参考对象去模仿,可以是自己欣赏的人.明星或模特等,直至最后 ...
- 新浪 ip 地址库
API地址:http://int.dpool.sina.com.cn/iplookup/iplookup.php 帮助 1 2 3 4 5 6 7 8 function get_location($i ...
- node进程捕捉错误
var childProcess = require('child_process'); var commitMessage = (function() { var spawn = childProc ...
- Spring Cloud 架构 五大神兽的功能
什么是微服务 微服务的概念源于2014年3月Martin Fowler所写的一篇文章“Microservices”. 微服务架构是一种架构模式,它提倡将单一应用程序划分成一组小的服务,服务之间互相协调 ...