CodeForces 27E Number With The Given Amount Of Divisors【反素数】

E. Number With The Given Amount Of Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 exceed1018.

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
4
output
6
input
6
output
12

题意:给你数N,计算反素数M使M的因子个数为N;

思路:用M的质因子建一棵树,每一层对应一个素因子,1e18范围内16个素因子就可以了,也即是说树有15层:0-14,1代表第-1层,递归搜索整棵树就行,需要剪枝(根据条件判断某一层到了某个节点后的都不用搜索了 一定不符合题意);

失误:写LUCAS时碰到的,国家开会 OJ都蹦了,学学反素数,搜索学的也不好,一天终于看懂了,但是打表的方法还是没有找出到底哪里出错了,实在想不出来了,记一下这一点不会,先往后学习!


AC代码:

#include<cstdio>

typedef unsigned long long LL;//适用于1e18范围内 
LL p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};//再多一个就车超1e18,也超LLU了,还需要考虑溢出 所以去掉了还省时间了 
LL ans,N;

void dfs(LL num,LL cnt,LL limit,LL pos)
{
	if(pos>=15) return ;// 0~14层 
	if(cnt==N&&ans>num) ans=num;//更新答案 
	LL i=0;
	for(i=1;i<=limit;++i)//枚举树的每一层 
	{
		if(cnt*(i+1)>N||num>ans/p[pos]) break;//剪枝条件 
		dfs(num*=p[pos],cnt*(i+1),i,pos+1);//递归搜索 
	 } 
 } 
int main()
{
	while(~scanf("%llu",&N))
	{
		ans=~(0LLU);//初始正无穷 
	    dfs(1,1,60,0);//根节点的值是1,深度-1 
		printf("%llu\n",ans); 
	 } 
	return 0;
 } 

这一题N只有1000 比较小 用打表侥幸过了,但是10^18内打表不成功,原因 啊,不想了,自己解决不了了;

#include<cstdio>
#include<cstring>
using namespace std;

typedef unsigned long long LL;
const  LL MAXN=1e5+1e4;

LL tp[MAXN],p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
const LL INF=1LLu<<60;
 
void Tp(LL num,LL cnt,LL limit,LL pos)
{
	if(pos>16) return ;
	if(tp[cnt]==0) tp[cnt]=num;
	if(tp[cnt]>num) tp[cnt]=num;
	LL tem=num,i=0;
	for(i=1;i<=limit;++i)
	{
		if(tem>INF/p[pos]) break;//防止溢出 
		tem*=p[pos];//作为一个节点的值 用于递推计算同一层后面节点的值 
		Tp(tem,cnt*(i+1),i,pos+1); 
	 } 
}
int main()
{
	LL T,N;  
	memset(tp,0,sizeof(tp));
	Tp(1,1,60,0);
		scanf("%llu",&N);
	    printf("%llu\n",tp[N]);
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值