Блог пользователя bvd

Автор bvd, история, 10 лет назад, По-английски

English version

Find all prime numbers between N and M, with 0 < N < M < 1025.

A further classification said that the time limit is 1 second and M - N < 109.

I'm wondering if there is a solution for this problem.

  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I'm not sure but I don't think there is a solution to this problem for 3 reasons.
1-) It is obvious that we can't iterate over those M-N numbers. It would be 5 * 108 by itself which would exceed 1 sec. run time limit.
2-) Since the numbers are too large we can't use prime sieves either, at least the ones I know.
3-) Even though we find the prime numbers in 0 sec, I assume we won't be able to print them out in 1 sec since there are probably more than 107 prime numbers between N and M in the worst case.
It would be great if someone can find a solution though.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

maybe BigInteger.nextProbablePrime() in java will work? not sure, though.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

http://www.wolframalpha.com/input/?i=prime+numbers+less+than+10^9

There are 50000000+ primes under 10^9 :( simply printing these will be a big challenge.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Actually the 2nd and 3rd problems in this paper were very easy, so I am quite sure that this problem was having some mistakes, or the actual tests' limits are small enough to brute force. Anyway this is the Vietnamese problems' style nowadays.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

Maybe use range sieve. It will require about sqrt(M) + (M-N) operations and bits of memory, even with inf memory this will take >> than 1 sec

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +37 Проголосовать: не нравится

Usually the trick to do well in middle school level competitions in Vietnam is to just ignore the unrealistic constraints.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится -29 Проголосовать: не нравится

this problem is not hard , just u r stupid