反素数的一些知识:
反素数是<=n的数中质因子数最多的并且最小的。
故有一下两个结论:
1.反素数必然是从2开始连续的若干个素数的若干幂的积:因为假设2*3*7*9,则一定存在2*3*5*7<2*3*7*9;
2.反素数的因子的幂,质因子越小,质因子的幂越大:因为假设2^4*3^6,必小于2^6*3^4,而它们的约数个数相同,都是(4+1)*(6+1);
具体看代码,一开始设的50是因为2^50已经大于10^16;
//============================================================================
// Name : zoj2562.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long ans, anssum, n;
int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
void dfs(long long curans,int now, long long cursum, int limit){
if(cursum > anssum){
ans = curans;
anssum = cursum;
}
else if(cursum == anssum&&curans < ans){
ans = curans;
}
if(now > 14) return ;
long long temp = curans;
for(int i = 1;i <= limit;i++){
if(curans*prime[now] > n){
break;
}
curans *= prime[now];
dfs(curans, now+1, cursum*(i+1), i);
}
}
int main(){
freopen("a.txt", "r", stdin);
while(scanf("%lld", &n)!=EOF){
ans = 1000000000000000;
anssum = 1;
dfs(1, 0, 1, 50);
printf("%lld\n", ans);
}
return 0;
}