import java.math.BigInteger; import java.util.Scanner; public class FindPrime{ public static void main(String [] args){ Scanner in = new Scanner(System.in); BigInteger N = new BigInteger(in.next()); BigInteger cnt = BigInteger.ONE; BigInteger res = N; boolean found = false; while (!found){ BigInteger cand1 = N.add(cnt); BigInteger cand2 = N.subtract(cnt); if (cand1.isProbablePrime(200)){ res = cand1; found = true; } else if (cand2.isProbablePrime(200)){ res = cand2; found = true; } cnt = cnt.add(BigInteger.ONE); } System.out.format("Nearest prime found is %s\n",res.toString()); } }