1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

int p[]={2,3,5,7,11,13,17,89,97,
	29,31,37,41,43,47,53,59,61,67,71,73,79,83,19,23};
ll n,m;
int d;
ll cnt=0,cnt2=0,pw=0;
const int T=1000000;
int p1[101000],p2[T+10];
ll ret;
void dfs1(int d,int x,int y,int v) {
	cnt++;
	if (x<=T) p2[x]=x; else p1[pw++]=x;
	for (int k=d;k<v;k++) {
		int ny=y/p[k];
		int nx=x;
		while (ny) {
			dfs1(k+1,nx*p[k],ny,v);
			ny/=p[k];
			nx*=p[k];
		}
	}
}
void dfs2(int d,ll x,ll y,int v) {
	if (y<=T) ret=max(ret,p2[y]*x);
	else ret=max(ret,(*(upper_bound(p1,p1+pw,y)-1))*x);
	for (int k=d;k<v;k++) {
		ll ny=y/p[k];
		ll nx=x;
		while (ny) {
			dfs2(k+1,nx*p[k],ny,v);
			ny/=p[k];
			nx*=p[k];
		}
	}
}

int main() {
	n=1000000000000000000ll-1;
	m=1000000000ll;

	pw=0;
	for (int i=1;i<=T;i++) p2[i]=0;
	dfs1(0,1,m,9);
	for (int i=1;i<=T;i++) p2[i]=max(p2[i],p2[i-1]);
	sort(p1,p1+pw);
	dfs2(9,1,n,25);

	pw=0;
	for (int i=1;i<=T;i++) p2[i]=0;
	dfs1(9,1,m,25);
	for (int i=1;i<=T;i++) p2[i]=max(p2[i],p2[i-1]);
	sort(p1,p1+pw);
	dfs2(0,1,n,9);
	printf("%lld\n",ret);
}