Number With The Given Amount Of Divisors CodeForces - 27E【反素数+dfs】
思路:反素数及其在OI中的应用 里面第一种类型
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define LL unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define MAXN 1005
int p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
int n;
LL ans=INF;
void dfs(int i/*第几个质数*/,LL tmp/*答案*/,int num/*因子个数*/)
{
if(num>n||i>=16) return ;
if(num==n&&tmp<ans) ans=tmp;
for(int j=1;j<=64;j++)//2^64>10^18
{
if(ans<tmp) break;
tmp*=p[i];
dfs(i+1,tmp,num*(j+1));
}
}
int main()
{
scanf("%d",&n);
dfs(0,1,1);
printf("%I64d\n",ans);
return 0;
}
转载请注明出处,有疑问欢迎探讨
博主邮箱 2775182058@qq.com