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 Specification
The first line will have the integer .
Output Specification
Print the number you want.
Sample Input
4
Sample Output
5
Comments
Didn't read input specs carefully enough, it got me good
I keep on getting TLE for the last few cases. I can't think of a faster way to do this problem using Python3.
I tried Wilson's Theorem but apparently that's too slow as well?
Any tips
HINT: There's a conclusion that for any positive integer , there must be a prime in the range of (I got this on google)
Actually when I was collecting interesting facts about prime numbers when doing my Math culminating work last semester, I found a conclusion that for any integer , there must be a prime number within the range of , and this may help you (And I finally passed this problem by using this property)
Your first approach is much better and can be fixed by just adding one thing (https://dmoj.ca/src/2209547).
Ask yourself this: do you need to check all the numbers up to to determine whether or not it is prime?
Does anyone know how to make my program run faster?
If you're using Java, you can use the BigInteger class because it has the method isProbablyPrime(), which checks if it's a prime pretty fast. I just incremented by 2 each time and checked if the resulting number is prime to get the next prime.
Yes, because that uses the miller-rabin primality test, which is time on average, where is the number of times the test is performed, which is generally a small constant number.
I suggest you read the comments
This comment is hidden due to too much negative feedback. Show it anyway.
The link didn't work for me but I know the answer, a number is prime if it has two factors and the only factor of one is 1 X 1.
This comment is hidden due to too much negative feedback. Show it anyway.
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):
This comment is hidden due to too much negative feedback. Show it anyway.
There seems to be a problem with your code. I know the site is correct. Not sure why this has happened. Please fix your code thanks.
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.
You know edits are visible to everyone, right?
This comment is hidden due to too much negative feedback. Show it anyway.
Time Limit Exceeded
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.
This comment is hidden due to too much negative feedback. Show it anyway.
The name of the problem might give a hint. Specifically, "Brute Force Practice 3".
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?
This comment is hidden due to too much negative feedback. Show it anyway.
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.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
Actually, there will not be an arrow if your program does not produce any output. That was what was really happening.
This comment is hidden due to too much negative feedback. Show it anyway.
Your code is incorrect. There is a corner case you missed.
This comment is hidden due to too much negative feedback. Show it anyway.
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.
This comment is hidden due to too much negative feedback. Show it anyway.
Inputs are integer only.
Not fair how
/^1?$|^(11+?)\1+$/
fails.it fails because
If only the memory limit was a few GB more and you had a few more days to run your program!
Lol