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

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

 
找出x的所有质因子表达式,最大长度就是各质因子指数的和,然后按照排列组合计算即可。
 
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn (1 << 20) + 5 typedef long long ll; int x,len = ;
bool prime[maxn];
int ele[]; ll cal(int x) {
ll ans = ;
for(int i = ; i <= x; i++) ans *= i; return ans;
} void init() {
for(int i = ; i <= maxn - ; i++) {
prime[i] = i % || i == ;
} for(int i = ; i * i <= maxn - ; i++) {
if(!prime[i]) continue;
for(int j = i; j * i <= maxn - ; j++) {
prime[j * i] = ;
}
} len = ;
for(int i = ; i <= maxn - ; i++) {
if(prime[i])
ele[len++] = i;
} }
int main() {
//freopen("sw.in","r",stdin); init(); while(~scanf("%d",&x)) {
if(prime[x]) {
printf("1 1\n");
} else {
int ans1 = ,len2 = ;
ll ans2 = ;
int num[];
for(int i = ; i < len && ele[i] <= x && x != ; i++) {
int sum = ;
if(x % ele[i] == ) {
while(x % ele[i] == ) {
ans1++;
sum++;
x /= ele[i];
}
num[len2++] = sum;
} } ans2 = cal(ans1);
for(int i = ; i < len2; i++) {
ans2 /= cal(num[i]);
}
printf("%d %I64d\n",ans1,ans2); } } return ;
}

POJ 3421的更多相关文章

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

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

  2. POJ 3421分解质因数

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

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

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

  4. POJ 3421 X-factor Chains

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

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

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

  6. POJ 3421 X-factor Chains | 数论

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

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

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

  8. ProgrammingContestChallengeBook

    POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...

  9. 一本通1628X-factor Chain

    1628:X-factor Chain 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自 POJ 3421 输入正整数 x,求 x 的大于 1 的因子 ...

随机推荐

  1. HashSet 读后感

    HashSet实现Set,是一个不能重复元素的集合,内部使用HashMap实现.因此具有HashMap的特性,如不保证元素插入的顺序,线程不安全,允许null.HashSet的元素就是内部HashMa ...

  2. NOIP 2015普及组复赛Day1 T1 == Codevs4510 神奇的幻方

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold  题目描述 Description: 幻方是一种很神奇的N∗N矩阵:它由数字 1,2,3, … … ,N∗N构成, ...

  3. windows通过thrift访问hdfs

    thirift是一个支持跨种语言的远程调用框架,通过thrift远程调用框架,结合hadoop1.x中的thriftfs,编写了一个针对hadoop2.x的thriftfs,供外部程序调用. 1.准备 ...

  4. C# 操作.ini文件

    1.声明变量 #region "声明变量" /// <summary> /// 写入INI文件 /// </summary> /// <param n ...

  5. keditor_php图片上传

    <script type="text/javascript" src="/statics/js/kindeditor/kindeditor-min.js" ...

  6. JavaScript 时间显示

    <span id="localtime"><span> <script type="text/javascript"> fu ...

  7. html 布局;css3+jq 下拉菜单;table分页动态添加行;html5本地存储;简单易用的html框架

    简单好用的html框架,预览图见最后: 源码: 1.页面布局使用table: table 嵌套 +iframe 布局: 2.下拉菜单为jq+css3 动画; css input 无边框,select下 ...

  8. Java HTML页面抓取实例

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  9. 【python】 入门 搭建环境

    1.去官网下载包 基本程序编译器 python-2.7.10.msi 集成开发环境 pycharm-community-4.5.2.exe 包管理工具 pip-7.0.3.tar.gz 2.安装 按顺 ...

  10. 2016 系统设计第一期 (档案一)MVC 控制器接收表单数据

    1.FormCollection collection   user.UserId =Convert.ToInt32(collection["UserId"]); /// < ...