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. C# 钱数 小写 转 大写

    public class Rmb { /// <summary> /// 转换人民币大小金额 /// </summary> /// <param name="n ...

  2. listagg wm_concat 行转列

    一. 这个写法和wm_concat相似,listagg(day,',')要把哪一列转换为同一行within group (order by day)同一行如何排序 with temp as ( ' d ...

  3. UIView maskView属性

    给View1的maskView 赋值View2 1.View2不会显示在View1上: 2.View2 的alpha通道会体现在View1上. 关于maskView,Apple的解释: An opti ...

  4. Codeforces Round #245 (Div. 1) B. Working out dp

    题目链接: http://codeforces.com/contest/429/problem/B B. Working out time limit per test2 secondsmemory ...

  5. ZY、

  6. Java进行Base64的编码(Encode)与解码(Decode)

    关于base64编码Encode和Decode编码的几种方式 Base64是一种能将任意Binary资料用64种字元组合成字串的方法,而这个Binary资料和字串资料彼此之间是可以互相转换的,十分方便 ...

  7. rxjs5.X系列 —— ErrorHandling/Condition/Mathematical系列 api 笔记

    欢迎指导与讨论 : ) 前言 本文是笔者翻译 RxJS 5.X 官网各类operation操作系列的的第四篇 —— ErrorHanding异常处理.Condition Operator情况操作.Ma ...

  8. jquery不能是使用普通的for循环 因为普通的for循环通过下表获取对象 如果通过下表获取对象的话 会转成dom对象

    jquery不能是使用普通的for循环 因为普通的for循环通过下表获取对象 如果通过下表获取对象的话 会转成dom对象

  9. MySQL二进制安装部署

    #使用二进制包安装mysql -linux-glibc2.-x86_64.tar.gz /data/ -linux-glibc2.-x86_64.tar.gz -C /data/ -linux-gli ...

  10. vdbench测试过程中遇到的小问题

    1.报Slave hd2-0 prematurely terminated 错误 首先根据提示查看hd2-0.stdout.html文件获取更多的错误信息,这个问题一般是未安装vdbench或者路径不 ...