X-factor Chains

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 7986 Accepted: 2546

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


解题心得:

  1. 题意就是给你一个数,要求你输出将这个数分解成因式相乘,并且后面一个因子至少是前面一个因子的2倍,问最长的因式相乘链有多长,有几条最长的因式相乘链。
  2. 其实就是将一个数分解成若干个素数相乘,因为后面分解出来的素数一定是在前面分解之后分解的,所以自然就大2倍以上。然后问有多少条链,其实就是问将所有因子的全排列有多少种,但是要除去重复因子的全排列。
  3. n个不同的数的全排列就是n!,除去重复的就是n!除以每个重复因子数的阶乘。

#include <map>
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll; map <int,int> prim_factor(ll n2) {
map<int,int> maps;
int N = n2;
for(int i=2;i*i<=N;i++) {
while(n2 % i == 0) {
maps[i]++;
n2 /= i;
}
}
if(n2 > 1)
maps[n2]++;
return maps;
}; ll mult(int k) {
ll ans = 1;
for(int i=2;i<=k;i++)
ans *= i;
return ans;
} int main() {
ll n;
while(scanf("%lld",&n) != EOF) {
map <int,int> :: iterator iter;
map <int,int> maps = prim_factor(n);
int len = 0;
for(iter=maps.begin();iter!=maps.end();iter++)
len += iter->second; ll ans = mult(len); for(iter=maps.begin();iter!=maps.end();iter++)
ans /= mult(iter->second);
printf("%d %lld\n",len,ans);
}
return 0;
}

POJ:3421-X-factor Chains(因式分解)(全排列)的更多相关文章

  1. POJ 3421 X-factor Chains (因式分解+排列组合)

    题意:一条整数链,要求相邻两数前一个整除后一个.给出链尾的数,求链的最大长度以及满足最大长度的不同链的数量. 类型:因式分解+排列组合 算法:因式分解的素因子个数即为链长,链中后一个数等于前一个数乘以 ...

  2. poj 3421 X-factor Chains——质因数分解

    题目:http://poj.org/problem?id=3421 记忆化搜索竟然水过去了.仔细一想时间可能有点不对,但还是水过去了. #include<iostream> #includ ...

  3. POJ 3421 X-factor Chains

    线型素数筛+质因素分解+组合数. AC后发现这样做效率有点低..766ms. #include<stdio.h> #include<string.h> #include< ...

  4. POJ 3421 X-factor Chains | 数论

    题意: 给一个x,求最长的排列满足开头是1,结尾是x,前一个数是后一个数的因子 输出长度和这样序列的个数 题解: 把x分解质因数,质因数个数就是答案,接下来考虑怎么求个数 显然这是一个可重集合全排列问 ...

  5. Mathematics:X-factor Chains(POJ 3421)

    X链条 题目大意,从1到N,1 = X0, X1, X2, …, Xm = X中间可以分成很多数,另Xi < Xi+1 Xi 可以整除Xi+1 ,求最大长度m和m长度的链有多少条 思路: 很简单 ...

  6. POJ 3421 X-factor Chains(构造)

    这条链依次乘一个因子.因为n<2^20,sqrt(n)分解因子,相同的因子相对顺序取一个. 组合公式计算一下就好. #include<cstdio> #include<iost ...

  7. POJ 3421分解质因数

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

  8. POJ 3421

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

  9. poj 1256 按一定顺序输出全排列(next_permutation)

    Sample Input 3aAbabcacbaSample Output AabAbaaAbabAbAabaAabcacbbacbcacabcbaaabcaacbabacabcaacabacbaba ...

  10. poj 3048 Max Factor(素数筛)

    这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个 ...

随机推荐

  1. js之静态方法与实例方法

    静态方法是指不需要声明类的实例就可以使用的方法. 实例方法是指必须要先使用"new"关键字声明一个类的实例, 然后才可以通过此实例访问的方法. function staticCla ...

  2. C++ 0x

  3. SQL SERVER 错误代码 0x534

    解决办法就是修改一下登陆名: ALTER LOGIN [G-PC\zqwang]   WITH NAME=[新的机器名\zqwang]; 然后查询一下 Service Broker 队列, 里面已经有 ...

  4. TP5.1:依赖注入、绑定一个类到容器里、绑定一个闭包到容器中

    依赖注入 1.在application中创建一个文件夹,名字为commom,commom文件夹中创建被注入文件夹,在被注入文件夹中创建一个名为demo.php的文件 2.在demo.php中输入: 3 ...

  5. *204. Count Primes (siecing prime)

    Count the number of prime numbers less than a non-negative number, n. Example: Input: 10 Output: 4 E ...

  6. Selenium入门19 捕获异常

    脚本出现异常时会中断执行,想要继续执行就要做异常处理: 1 try ... except .... else   遇到异常显示异常信息: 没有异常继续执行else后面的脚本 2 try ... exc ...

  7. 有一个form,包含两个text,和两个按钮,当用户按第一个按扭时把数据提交到url1,按第二个按钮提交到url2,怎么实现呀?

    <form name="form1" method="post" action=""> <input type=" ...

  8. 广搜,深搜,单源最短路径,POJ(1130),ZOJ(1085)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=85 http://poj.org/problem?id=1130 这 ...

  9. 【转】Xcode真机调试初体验

    1. 开发者证书(Certificates) 分为开发(iOS Development)和发布(iOS Distribution)两种,无论是真机调试,还是上传到App Store都需要该证书,是一个 ...

  10. 奇异值分解(SVD)原理及应用

    一.奇异值与特征值基础知识: 特征值分解和奇异值分解在机器学习领域都是属于满地可见的方法.两者有着很紧密的关系,我在接下来会谈到,特征值分解和奇异值分解的目的都是一样,就是提取出一个矩阵最重要的特征. ...