先上一篇大佬的文章学习一下反素数的概念
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smallest positive integer with exactly n divisors.
Examples
input
Copy
4output
Copy
6input
Copy
6output
Copy
12
思路:真正的看完上面的文章之后这个题应该只算一个模板题了,
AC代码:
#include<cstdio>
#include<iostream>
using namespace std;
int prime[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
long long ans;
int n;
void dfs(int index,long long temp,int num)
{
if(num>n||index>=16) return;
if(num==n&&temp<ans) ans=temp;
for(int i=1;i<64;i++)
{
if(temp>ans) break;
dfs(index+1,temp*=prime[index],num*(i+1));
}
}
int main()
{
scanf("%d",&n);
ans=1000000000000000001;
dfs(0,1,1);
printf("%lld\n",ans);
return 0;
}