CodeForces - 27E
求约数个数为N的最小的数
这样的数一定是反素数,但不知道反素数也不要紧
用DFS从小到大枚举质数表中的每一个质数
然后乘起来,计算能组成的约数的个数
加两个剪枝,一是约数个数大于N的
二是继续增加这个质数的个数,但无法更新答案的
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Pow2(a) (a*a)
const int tprm[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
int N;
ULL ans;
void dfs(int,int,ULL);
int main()
{
scanf("%d", &N);
ans=~0ULL;
dfs(0,1,1);
printf("%I64u\n", ans);
return 0;
}
void dfs(int np, int cnt, ULL now)
{
if(cnt>N) return;
if(cnt==N) ans=min(ans, now);
for(int i=1; i<64; i++)
{
if(ans/tprm[np]<now) break; // prune
now*=tprm[np];
dfs(np+1,cnt*(i+1),now);
}
}