1. 程式人生 > >[POI2002][HAOI2007]反素數 數論 搜索 好題

[POI2002][HAOI2007]反素數 數論 搜索 好題

指數 input include name rime pre 好題 turn long long

Code:

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int prime[]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,51,53};
ll n, maxn;
int cur;
void dfs(int dep,ll m,int t,int p){  //上一個指數
	if(dep==12){
		if(t>=cur){
			if(t>cur) maxn=m, cur=t; 
			else if(m<maxn) maxn=m;
		}
		return;
	}
	ll cnt=1;
	for(int i=0;i<=p;++i){
		dfs(dep+1,m*cnt,t*(i+1),i);
		cnt*=prime[dep];
		if(m*cnt>n) break;
	}
}
int main(){
	//freopen("input.in","r",stdin);
	scanf("%lld",&n);
	dfs(1,1,1,30);
	printf("%lld",maxn);
	return 0;
}

  

[POI2002][HAOI2007]反素數 數論 搜索 好題