import java.util.Arrays;
import java.util.Scanner;
class Main {
static int[] pri = new int[100];
static int idx;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
init();
// System.out.println(nearprime(x));
// System.out.println(nearprime(97 - x));
System.out.println(nearprime(x) * nearprime(97 - x));
}
private static void init() {
for (int i = 2; i <= 100; i ++ ) {
int now = i;
boolean f = true;
for (int j = 2; j <= now / j; j ++ ) {
if (now % j == 0) f = false;
}
if (f) pri[idx ++ ] = now;
}
}
private static int nearprime(int x) {
int fl = 0, fr = idx - 1;
while (fl < fr) {
int mid = fl + fr + 1 >> 1;
if (pri[mid] <= x) fl = mid;
else fr = mid - 1;
}
int sl = 0, sr = idx - 1;
while (sl < sr) {
int mid = sl + sr >> 1;
if (pri[mid] >= x) sr = mid;
else sl = mid + 1;
}
int dx = 0x3f3f3f3f;
if (pri[fl] <= x) dx = Math.abs(x - pri[fr]);
int dy = 0x3f3f3f3f;
if (pri[sl] >= x) dy = Math.abs(x - pri[sr]);
// if (x == 15) {
// System.out.println("debug dx -> " + dx);
// System.out.println("debug dy -> " + dy);
// }
if (dx <= dy) return pri[fl];
return pri[sr];
}
}
标签:二分,int,质数,pri,System,3097,dx,println,out
From: https://www.cnblogs.com/llihaotian666/p/17857244.html