如何构造一个具有特定因数数量的数?
- 内容介绍
- 文章标签
- 相关推荐
本文共计928个文字,预计阅读时间需要4分钟。
题目:给定一个整数n,找出最小的正整数,它恰好有n个约数。保证对于给定的n,答案不会超过1018。
输入:输入的第一行包含一个整数n(1≤n≤1018)。
题干:
Given the numbern, find the smallest positive integer which has exactlyndivisors. It is guaranteed that for the givennthe answer will not exceed1018.
Input
The first line of the input contains integern(1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactlyndivisors.
Examples
Input
4
Output
6
Input
6
Output
12
题目大意:
给定一个正整数n,求一个最小的正整数,使得它的因子个数恰为n。保证答案不超过1018
解题报告:
这题用到了一个概念叫反素数、、学习了一波。,但是其实就算没有这个概念,做法也很显然吧,,做个唯一分解这题就做完了。知识点在下面附上了。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll biao[55] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
ll minn = 1e18+5;
ll n;
void dfs(ll dep,ll tmp,ll cur) {
if(cur > n) return ;
if(cur==n) minn = min(tmp,minn);
for(ll i = 1; i<=63; i++) {
if(minn < tmp * biao[dep]) break;
tmp = tmp * biao[dep];
dfs(dep+1,tmp,cur*(i+1));
}
}
int main()
{
int t;
cin>>n;
dfs(0,1,1);
printf("%lld\n",minn);
return 0 ;
}
知识点:反素数:来源链接
今天要我要讲的是反素数,在ACM中也算是常见的考点,那么对于搞ACM的同学来说,很有必要搞清楚它,所以接下
来我会很详细地讲解。
在讲解反素数之前,我们先来看反素数的概念。
反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整
数,都有,那么称为反素数。
从反素数的定义中可以看出两个性质:
(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为的这个数尽量小
(2)同样的道理,如果,那么必有
在ACM竞赛中,最常见的问题如下:
(1)给定一个数,求一个最小的正整数,使得的约数个数为
(2)求出中约数个数最多的这个数
从上面的性质中可以看出,我们要求最小的,它的约数个数为,那么可以利用搜索来解。
以前我们求一个数的所有因子也是用搜索,比如,以每一个为树的一层建立搜索树,深度为
以为例进行说明,建树如下:
可以看出从根节点到每一个叶子结点这条路径上的所有数字乘起来都是12的约数,所以12有6个约数。
本文共计928个文字,预计阅读时间需要4分钟。
题目:给定一个整数n,找出最小的正整数,它恰好有n个约数。保证对于给定的n,答案不会超过1018。
输入:输入的第一行包含一个整数n(1≤n≤1018)。
题干:
Given the numbern, find the smallest positive integer which has exactlyndivisors. It is guaranteed that for the givennthe answer will not exceed1018.
Input
The first line of the input contains integern(1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactlyndivisors.
Examples
Input
4
Output
6
Input
6
Output
12
题目大意:
给定一个正整数n,求一个最小的正整数,使得它的因子个数恰为n。保证答案不超过1018
解题报告:
这题用到了一个概念叫反素数、、学习了一波。,但是其实就算没有这个概念,做法也很显然吧,,做个唯一分解这题就做完了。知识点在下面附上了。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
ll biao[55] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
ll minn = 1e18+5;
ll n;
void dfs(ll dep,ll tmp,ll cur) {
if(cur > n) return ;
if(cur==n) minn = min(tmp,minn);
for(ll i = 1; i<=63; i++) {
if(minn < tmp * biao[dep]) break;
tmp = tmp * biao[dep];
dfs(dep+1,tmp,cur*(i+1));
}
}
int main()
{
int t;
cin>>n;
dfs(0,1,1);
printf("%lld\n",minn);
return 0 ;
}
知识点:反素数:来源链接
今天要我要讲的是反素数,在ACM中也算是常见的考点,那么对于搞ACM的同学来说,很有必要搞清楚它,所以接下
来我会很详细地讲解。
在讲解反素数之前,我们先来看反素数的概念。
反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整
数,都有,那么称为反素数。
从反素数的定义中可以看出两个性质:
(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为的这个数尽量小
(2)同样的道理,如果,那么必有
在ACM竞赛中,最常见的问题如下:
(1)给定一个数,求一个最小的正整数,使得的约数个数为
(2)求出中约数个数最多的这个数
从上面的性质中可以看出,我们要求最小的,它的约数个数为,那么可以利用搜索来解。
以前我们求一个数的所有因子也是用搜索,比如,以每一个为树的一层建立搜索树,深度为
以为例进行说明,建树如下:
可以看出从根节点到每一个叶子结点这条路径上的所有数字乘起来都是12的约数,所以12有6个约数。

