Next Prime (Hard)

View as PDF

Submit solution


Points: 15
Time limit: 2.0s
Memory limit: 64M

Problem type

Allowed languages
Ada , Assembly , Awk , Brain**** , C , C++ , COBOL , CommonLisp , Dart , Erlang , Forth , Fortran , Intercal , Lisp , Octave , Pascal , Prolog , R , Racket , Rust , Scheme , Sed , TCL , Text , Turing , VB

Brute Force Practice 3 — Hard Version

You love prime numbers. You own a number, but you suspect it might not be prime. You want a prime number, but it must be at least as large as the number you currently own. Find the smallest number that satisfies those conditions.

Input

The first line will have the integer N (1 \le N \le 10^{18})

Output

Print the number you want.

Sample Input

4

Sample Output

5

Comments


  • 1
    1419903188  commented on Oct. 8, 2017, 11:14 a.m.

    Hint

    can I have any hints?

    keep getting WA MLE and TLE.


    • 8
      aeternalis1  commented on Oct. 8, 2017, 12:59 p.m.

      Your code is wrong, takes up too much memory, and is too slow.


      • 1
        1419903188  commented on Nov. 15, 2017, 10:43 p.m.

        Thx man.

        I'm probably just gonna learn some math.


  • 0
    BonyBen  commented on Oct. 4, 2017, 10:07 p.m.

    Why is java disabled?


    • -1
      Kirito  commented on Oct. 4, 2017, 11:13 p.m.

      java.math.BigInteger has a method called isProbablePrime(), which would trivialize the problem.


      • 0
        BonyBen  commented on Nov. 13, 2017, 7:53 p.m.

        oh ok


  • -7
    cranberrysauce26  commented on April 16, 2017, 1:57 a.m.

    I think there might be a problem with the online grader cuz I got the results for test cases 1 to 10:

    1. 0.007s
    2. 0.008s
    3. 0.006s
    4. 0.008s
    5. 0.008s
    6. 0.009s
    7. 0.010s
    8. 0.011s
    9. 0.010s
    10. 0.013s

    and in my submissions, it says my time is 0.09s. I calculated the average to be 0.009s, so I think the grader is multiplying by 10 for some reason.

    I did not misread the decimal places btw. Thanks!


    • 5
      wleung_bvg  commented on April 16, 2017, 3:41 a.m.

      The time is the total time, not the average


  • 4
    println_hi_  commented on Oct. 15, 2016, 1:44 p.m.
    Python disabled?

    What is submitting code in python not allowed for this problem?


    • 0
      kipply  commented on June 1, 2017, 11:08 a.m.

      Can we have Python <3


    • -6
      xxX_V1Ct0R_Xxx  commented on Jan. 21, 2017, 5:35 p.m.

      Cus we dont liek python........ its bad... :P


  • 0
    parkjs814  commented on Sept. 18, 2016, 2:08 a.m.
    aa

    x^2


  • 1
    FatalEagle  commented on March 23, 2015, 8:10 p.m.
    No partial output

    Partial output is disabled for this problem.