Next Prime

View as PDF

Submit solution

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

Problem type
Brute Force Practice 3

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 2 \times 10^9)

Output

Print the number you want.

Sample Input

4

Sample Output

5

Comments


  • 0
    LiFengxun  commented on Oct. 13, 2018, 9:31 a.m.

    Need hint???

    It is very easy for java you just need to check the math sqrt of a int n, or else, you will exceed the time limit


  • -12
    alexzhang  commented on June 27, 2018, 8:44 p.m.

    I always thought one was a prime number.....


  • -7
    nishux  commented on Nov. 14, 2017, 7:19 p.m. edited

    There seems to be a problem with test case #2 and #6 when I run my code. Can someone please check my test cases.


    • 14
      injust  commented on Nov. 15, 2017, 11:21 p.m.

      Instead of suggesting that correct solutions from 400+ other users are flawed, you may want to take another look at the problem statement (emphasis mine):

      You want a prime number, but it must be at least as large as the number you currently own.


      • 6
        nishux  commented on Nov. 28, 2017, 4:16 p.m.

        Didn't mean to say that the test cases were wrong. I just didn't know what was wrong with my code.Sorry for the miscommunication.


  • -17
    Anix55  commented on Oct. 15, 2015, 8:31 p.m.
    TLE

    what does TLE mean?


    • 4
      Xyene  commented on Oct. 15, 2015, 8:37 p.m.

      It means your program has exceeded the per-testcase time limit (in this case, 2 seconds). You can hover over status codes, as their alt text provides more details on what they are.


  • -6
    bobhob314  commented on Jan. 6, 2015, 5:08 p.m.
    Sieve?

    Are there any pointers you could give me to solve this question? Should I use the Sieve or something? I'm stuck :(


    • 4
      FatalEagle  commented on Jan. 6, 2015, 5:55 p.m.

      The name of the problem might give a hint. Specifically, "Brute Force Practice 3".


  • 5
    FatalEagle  commented on Nov. 14, 2014, 2:29 p.m.
    Hint

    Even though this is Brute Force Practice 3, you still need a little optimization -- for example, can you determine if a number is prime just by checking divisors up to and including the square root of a number?


  • -9
    BMP  commented on Nov. 14, 2014, 3:34 a.m.
    dafuq

    Keep getting 90%, first test fails. What...


    • 3
      FatalEagle  commented on Nov. 14, 2014, 11:27 a.m.

      Partial output has been enabled. You can see what output your program produced (up to about 32 bytes for now) and try to debug your code.


      • -7
        PaulOlteanu  commented on Nov. 24, 2014, 10:06 p.m.

        Has the output been disabled?


        • -9
          PaulOlteanu  commented on Nov. 24, 2014, 10:08 p.m.

          Nevermind. It seems the output only displays if you have less than a certain number of mistakes.


          • 5
            FatalEagle  commented on Nov. 24, 2014, 10:51 p.m.

            Actually, there will not be an arrow if your program does not produce any output. That was what was really happening.


  • -7
    Yuting9  commented on Oct. 27, 2014, 8:47 p.m.
    Last One Lucky

    I can't seem to get the last test to work for my code...


    • 3
      FatalEagle  commented on Oct. 27, 2014, 9:13 p.m.

      Your code is incorrect. There is a corner case you missed.


      • -7
        Yuting9  commented on Oct. 27, 2014, 9:59 p.m.

        what do you mean, "corner case?"


        • 3
          FatalEagle  commented on Oct. 27, 2014, 10:01 p.m.

          If I wrote it here, it wouldn't be a corner case anymore. Make sure your solution is valid for all possible inputs within the range specified.


  • -2
    JannyWang  commented on Oct. 16, 2014, 9:28 p.m.
    Janny

    Does it have to work for decimals?


    • 3
      quantum  commented on Oct. 16, 2014, 11:32 p.m.

      Inputs are integer only.


  • 5
    quantum  commented on Sept. 27, 2014, 9:59 p.m.
    Not fair

    Not fair how /^1?$|^(11+?)\1+$/ fails.


    • 1
      simohamedd  commented on May 5, 2018, 4:51 a.m.

      it fails because public class Piggy {public static int nextPrime(int n) {System.out.println(nextPrime(n));} return %$a++;


    • 17
      FatalEagle  commented on Sept. 27, 2014, 11:43 p.m.

      If only the memory limit was a few GB more and you had a few more days to run your program!


      • 6
        MateiG  commented on June 19, 2017, 12:57 p.m.

        Lol