package no371; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static ArrayList primeList = primeList(110000); //嘘っぽい public static void main(String[] args) { Scanner sc = new Scanner(System.in); long l = sc.nextLong(); long h = sc.nextLong(); System.out.println(better(l,h)); // long r = 10000000000L; // while(true) { // long stime = System.nanoTime(); // long ans = better(3,r); // System.out.println(r + "->" + ans); // System.out.println((System.nanoTime() - stime) / 1000000 + " ms"); // System.out.println("factorize:" + primeFactorL(primeList, ans)); // r = ans - 1; // } } public static long better(long l,long h) { if (h - l <= 100) { return naive(l, h); } long x = -1; for(long p: primeList) { long sq = p * p; if (sq > h) { break; } if (l <= sq) { x = p; } } if (x < 0) { return naive(l,h); } long ans = x * x; for(long p: primeList) { long y = x * p; if (y <= h && y >= ans) { ans = y; } } return ans; } public static long naive(long l,long h) { int best = -1; long ans = Long.MAX_VALUE; for(long n=h;n>=l;n--) { if (best >= 0) { long p = primeList.get(best + 1); // System.out.println(n - p * p); if (p * p > n) { break; } } int ind = -1; for(int i=0;i best) { best = ind; ans = n; } } return ans; } public static boolean[] isPrimeArray(int max) { boolean[] isPrime = new boolean[max+1]; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for(int i=2;i*i<=max;i++) { if (isPrime[i]) { int j = i * 2; while(j<=max) { isPrime[j] = false; j += i; } } } return isPrime; } public static ArrayList primeList(int max) { boolean[] isPrime = isPrimeArray(max); ArrayList primeList = new ArrayList(); for(int i=2;i<=max;i++) { if (isPrime[i]) { primeList.add(i); } } return primeList; } public static ArrayList primeFactorL(ArrayList primeList,long num) { ArrayList ret = new ArrayList(); for(int p:primeList) { while(num % p == 0) { num /= p; ret.add((long) p); } } if (num > 1) { ret.add(num); } return ret; } }