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. java基础之bit、byte、char、String

    bit 位,二进制数据0或1 byte 字节,一个字节等于8位二进制数 char 字符, String 字符串,一串字符 常见转换 1 字母  = 1byte = 8 bit 1 汉字  = 2byt ...

  2. mongodb $where 查询中的坑

    mongodb 查询中坑就是数字开头的字段不能用点号,只能用[""].例如: 即:db.datas.find({$where:"this['54bcfc6c329af61 ...

  3. 树 List Leaves 【用数组模拟了树状结构建树+搜索叶子节点+按照特殊规律输出每个叶子节点】

    Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...

  4. 使用 Apache Spark 让 MySQL 查询速度提升 10 倍以上

    转: https://coyee.com/article/11012-how-apache-spark-makes-your-slow-mysql-queries-10x-faster-or-more ...

  5. EntityFramework 学习 一 Colored Entity in Entity Framework 5.0

    You can change the color of an entity in the designer so that it would be easy to see related groups ...

  6. git终端配置颜色

    默认情况下git是黑白的. git config --global color.status auto git config --global color.diff auto git config - ...

  7. How to use the ZooKeeper driver for ServiceGroup in OpenStack Nova

    ServiceGroup APIs Nova会从ServiceGroup API 中查询节点的存活信息. ServiceGroup API 工作流程是: 当一个compute worker (runn ...

  8. LAMP环境搭建问题

    //////////////////////////LAMP环境搭建问题///////////////////////////////////////LAMP常见的问题A.安装相关问题(1)MySQL ...

  9. C++中int转string与string转int

    #include "stdafx.h" #include "string" #include "iostream" #include &qu ...

  10. 使用memcache 心得和注意事项

    内存分配机制:首先要说明的是Memcached支持最大的存储对象为1M.它的内存分配比较特殊,但是这样的分配方式其实也是对于性能考虑的,简单的分配机制可以更容易回收再分配,节省对于CPU的使用.这里用 ...