HDU 4228

很明显可以转化为反素数的题目。由于有n种不同的方式,所以,数的约数可以为2*n或者2*n-1

#include <iostream>
#include <cstdio>
#include <cstring>
#define LL __int64

using namespace std;

LL p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};  
LL n,k;

void dfs(LL dep,LL tmp,LL num, LL &ans){
	if(num>k) return;
	if(num==k){
		if(tmp<ans)
		ans=tmp;
		return ;
	}
	for(LL i=1;i<=60;i++){
		if(tmp*p[dep]>ans) break;
		tmp*=p[dep];
		dfs(dep+1,tmp,num*(i+1),ans);
	}
}

int main(){
	while(scanf("%I64d",&n),n){
		k=2*n;
		LL ansi=(1LL<<60);
	//	cout<<ansi<<endl;
		dfs(0,1,1,ansi);
	//	cout<<ansi<<endl;
		k=2*n-1;
		LL ansj=(1LL<<60);
		dfs(0,1,1,ansj);
	//	cout<<ansj<<endl;
		printf("%I64d\n",ansi<ansj?ansi:ansj);
	}
	return 0;
}

  

posted @ 2014-09-06 20:08  chenjunjie1994  阅读(148)  评论(0编辑  收藏  举报