POJ3421(质因数分解)
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 = 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
思路:将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(质因数分解)的更多相关文章
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- 求n!质因数分解之后素数a的个数
n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...
- AC日记——质因数分解 1.5 43
43:质因数分解 总时间限制: 1000ms 内存限制: 65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...
- 【BZOJ-4514】数字配对 最大费用最大流 + 质因数分解 + 二分图 + 贪心 + 线性筛
4514: [Sdoi2016]数字配对 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 726 Solved: 309[Submit][Status ...
- 整数分解 && 质因数分解
输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
- POJ1365 - Prime Land(质因数分解)
题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符 ...
- 数学概念——J - 数论,质因数分解
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu1405 第六周J题(质因数分解)
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
随机推荐
- 20145240 《Java程序设计》第三次实验报告
20145240 <Java程序设计>第三次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验日期:2016.04.22 实验 ...
- maven setting.xml 存放位置导致deply失败,显示没有权限401错误
settings.xml存在于两个地方: 1.安装的地方:$M2_HOME/conf/settings.xml 2.用户的目录:${user.home}/.m2/settings.xml 我只在mav ...
- Qt QSortFilterProxyModel示例代码, 使用方法
1. QSortFilterProxyModel不能单独使用,它只是一个"代理",真正的数据需要另外的一个model提供,而且它是用来排序和过滤的. 2. 实现代码 #ifndef ...
- eclipse安装hibernate插件(在线Marketplace中安装)
网上很多都是给个网址,然后在eclipse的help中new install soft中安装.每次安装还要去查找最新的地址去安装.为什么不用eclipse的marketplace直接搜索安装呢? 打开 ...
- StringToInt(atoi) 字符串转换成整数
public class StringToInt { public int atoi(String s) { long num = 0; int minus = 0; if(s==null) { re ...
- 使用roboware创建工作空间
1.打开终端,启动roboware软件: $roboware-studio 2.在欢迎使用的页面点新建工作区,工作区的名字建议写为:catkin_ws,路径放在home文件夹或者任意你想放的文件夹中. ...
- js字符串转dom
function parse2dom(str){ var div = document.createElement("div"); if(typeof str == "s ...
- Codeforces 938E Max History:排列 + 逆元【考虑单个元素的贡献】
题目链接:http://codeforces.com/problemset/problem/938/E 题意: 定义f(a): 初始时f(a) = 0, M = 1. 枚举i = 2 to n,如果a ...
- open inventor 学习笔记
初次接触open inventor,跟以前学习一种新的东西,都想要先做出个小的helloworld程序,这个当然也不例外. 首先会创建一个窗口句柄,初始化一下场景数据库. HWND window = ...
- 如何学习Android系统源码(转)
一. Android系统的源代码非常庞大和复杂,我们不能贸然进入,否则很容易在里面迷入方向,进而失去研究它的信心.我们应该在分析它的源代码之前学习好一些理论知识,下面就介绍一些与Android系统相关 ...