X-factor Chains
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6501   Accepted: 2023

Description

Given a positive integer X, an X-factor chain of length m is a sequence of integers,

1 = X0X1X2, …, 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
思路:将x进行质因数分解,X-factor Chains中(第因一项永为1,所以不计)第i项就是将质因数进行排列后前i项的积。所以length为质因数的个数。numbeu为质因数全排列的种数。相同质因数之间的排列要去重。
#include <iostream>
#include <map>
using namespace std;
typedef unsigned long long ull;
map<int,int> prime_factor(int n)//质因数分解
{
map<int,int> res;
for(int i=;i*i<=n;i++)
{
while(n%i==)
{
res[i]++;
n/=i;
}
}
if(n!=)
{
res[n]++;
}
return res;
}
ull fact(int n)
{
ull res=;
for(int i=;i<=n;i++)
{
res*=i;
}
return res;
}
int x;
int main()
{
while(cin>>x)
{
map<int,int> res=prime_factor(x);
int len=;
for(map<int,int>::const_iterator it=res.begin();it!=res.end();it++)
{
len+=it->second;
}
ull cnt=fact(len);
for(map<int,int>::const_iterator it=res.begin();it!=res.end();it++)
{
cnt/=fact(it->second);//去重
}
cout<<len<<" "<<cnt<<endl;
}
return ;
}

POJ3421(质因数分解)的更多相关文章

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

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

  2. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  3. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

  4. 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛

    4514: [Sdoi2016]数字配对 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 726  Solved: 309[Submit][Status ...

  5. 整数分解 && 质因数分解

    输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...

  6. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  7. POJ1365 - Prime Land(质因数分解)

    题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...

  8. 数学概念——J - 数论,质因数分解

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  9. hdu1405 第六周J题(质因数分解)

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Desc ...

随机推荐

  1. Objective-C与Swift的混合编程

    Swift 被设计用来无缝兼容 Cocoa 和 Objective-C .在 Swift 中,你可以使用 Objective-C 的 API(包括系统框架和你自定义的代码),你也可以在 Objecti ...

  2. linux安装Zabbix监控

    源码包3.4.0下载  https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.0/zabbix-3.4 ...

  3. Luogu-4248 [AHOI2013]差异

    \(\sum_{i<j}len(i)+len(j)\)比较简单,稍微想想就出来了,问题在于怎么求任意两个后缀的\(lcp\)长度之和 因为求\(lcp\)实际上就是一个对\(h\)数组求区间最小 ...

  4. 简介web服务器的工作原理

    一 什么是web服务器,应用服务器和web容器? 对于web服务器与应用服务器:“在过去它们是有区别的,但是这两个不同的分类慢慢地合并了,而如今在大多在情况下和使用中可以把它们看成一个整体.” 但是当 ...

  5. IOS 拨打电话:4006 701 855 苹果中国

    IOS 拨打电话:4006 701 855 苹果中国

  6. uvalive 6938 区间dp

    看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...

  7. Eclipse下创建简单Servlet

    参考文章:一个简单的Servlet程序  http://blog.csdn.net/a153375250/article/details/50916428 Servlet简介 Servlet是什么?简 ...

  8. hibernate报错org.hibernate.SessionException: Session was already closed

    org.hibernate.SessionException: Session was already closedat org.hibernate.internal.SessionImpl.clos ...

  9. ODPS中的TaskContext类里面的write函数

    ODPS中的TaskContext类有几个write函数 write(Record record)用来输出到默认输出表 write(Record record, String label)用来输出的l ...

  10. node-并发控制

    当我们在做一些爬虫小程序的时候,如果我们一次性爬的数据条较多,那么相关软件也许会有限制或者是认为我们是非法的.那么我们就需要一些机制去限制获取数据的条数.而且node为我们提供的并发获取数据都是异步的 ...