1. 程式人生 > >反素數學習~Codeforces 27E (模板題)

反素數學習~Codeforces 27E (模板題)

先上一篇大佬的文章學習一下反素數的概念

https://www.cnblogs.com/liuweimingcprogram/p/5877411.html

 

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

4

output

Copy

6

input

Copy

6

output

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;
}