Under construction

Still being built. Things may change

Consecutive Primes

Interview

Time limit15sMemory limit1024 MB

Summary
For each query Z, find the largest product of two consecutive primes that does not exceed Z.
Level

Medium4 of 10

Topics
Number theory, Math, Binary search, Brute force
Solved
No attempts yet

Problem

Ada has bought a secret present for her friend John. To open the present, John must crack a secret code. Ada decides to give him a hint to make things simple for him. She tells him that the secret code is a number that can be formed by taking the product of two consecutive prime numbers, such that it is the largest number that is smaller than or equal to ZZ. Given the value of ZZ, help John determine the secret code.

Formally, let the order of prime numbers 2, 3, 5, 7, 11, ... be denoted by p_1p\_1, p_2p\_2, p_3p\_3, p_4p\_4, p_5p\_5, ... and so on. Consider R_iR\_i to be the product of two consecutive primes p_ip\_i and p_i+1p\_{i+1}. The secret code is the largest R_jR\_j such that R_j≤ZR\_j \le Z.

Input

The first line of the input gives the number of test cases, TT. TT lines follow.

Each line contains a single integer ZZ, the number Ada gives as part of the hint.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the secret code, the largest number less than or equal to ZZ that is the product of two consecutive prime numbers.

Limits

  • 1≤T≤1001 \le T \le 100.

Hint

For sample case #1, the secret code is 2021 because it is exactly the product of consecutive primes 43 and 47.

For sample case #2, the secret code is 1763 because the product of 41 and 43 is 1763, which is smaller than 2020, but the product of 43 and 47 exceeds the given value 2020.

Examples1

  1. Example 1

    Input
    2
    2021
    2020
    
    Expected output
    Case #1: 2021
    Case #2: 1763