码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4228

时间:2014-09-06 21:13:13      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   div   sp   log   amp   c   

很明显可以转化为反素数的题目。由于有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;
}

  

HDU 4228

标签:blog   os   io   for   div   sp   log   amp   c   

原文地址:http://www.cnblogs.com/jie-dcai/p/3959753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!