ZOJ 2562

想了半天 想不到什么正解、、随便搞下、、竟然不科学的没超时的过了、、

我用个map记录、、对于从第i个素数开始 能构成不小于n的数,最大divisor有多少,并且最小这个数十多少、、

然后枚举记忆化下、、、没超时 我都觉得不科学了

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;
typedef long long LL;
map< pair <LL, LL >, pair<LL , LL> > mp;
LL n;
LL prime[50010], is[50010];
void getprime(){
	int cnt = 0;
	for(int i = 2; i <= 50000; i++){
		if( !is[i] ){
			prime[cnt++]=i;
			for(int j = i; j <= 50000; j += i)
				is[j]=1;
		}
	}
}
LL pow(LL x, LL y){
	LL tmp = 1;
	while(y){
		if(y & 1) tmp = tmp * x;
		x = x * x;
		y >>= 1;
	}
	return tmp;
}
LL dfs(LL i, LL n){
	if( mp.count(make_pair(i, n)) ) 
		return mp[ make_pair(i, n) ].first;
	if(prime[i] > n){
		mp[ make_pair(i, n) ].first = 1;
		mp[ make_pair(i, n) ].second = 1;
		return 1;
	}
	LL tmp = prime[i] , cnt = 0, ans = 0;
	while( tmp <= n ){
		cnt++;
		if(ans < (cnt + 1) * dfs(i+1, n / tmp)){
			mp[ make_pair(i, n) ].second = tmp * mp[ make_pair(i+1, n / tmp) ].second;
			ans = (cnt + 1) * mp[ make_pair(i+1, n / tmp) ].first;
		}
		else {
			if( ans == (cnt + 1) * mp[ make_pair(i+1, n / tmp) ].first)
				if(mp[ make_pair(i, n) ].second > tmp * mp[ make_pair(i+1, n / tmp)].second)
				mp[ make_pair(i, n) ].second = tmp * mp[ make_pair(i+1, n / tmp)].second;
		}
		tmp *= prime[i];
	}
	return mp[ make_pair(i,n) ].first = ans;
}
int main(){
	getprime();
	mp.clear();
	while(~scanf("%lld",&n)){
		dfs(0, n);
		printf("%lld\n", mp[ make_pair(0,n)].second);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值