Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Problem {
- private static final int N = 300000;
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int d = sc.nextInt();
- long result = helpMocha(d);
- System.out.println(result);
- }
- static boolean[] isPrime = new boolean[N+1];
- static ArrayList<Long> primes = new ArrayList<>();
- static void sieve(){
- for(long i=2; i <= N; i++){
- if(isPrime[(int)i]){
- for(long j = i*i; j <= N; j += i){
- isPrime[(int)j] = false;
- }
- primes.add(i);
- }
- }
- }
- static long lowerBound(ArrayList<Long> list, long x){
- int n = list.size();
- int lo = 0, hi = n-1, res = n-1;
- while (lo <= hi){
- int mid = lo + (hi - lo)/2;
- if(list.get(mid) == x)
- return x;
- else if(list.get(mid) > x){
- res = mid;
- hi = mid-1;
- }else{
- lo = mid+1;
- }
- }
- return list.get(res);
- }
- static long helpMocha(int d){
- Arrays.fill(isPrime, true);
- sieve();
- long a = lowerBound(primes, 1 + d);
- long b = lowerBound(primes, a + d);
- return a*b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement