1 / 3
Mar 2018

My code is executing properly but the problem for the last output if press keyboard enter only its printing output. i have tried for past three day i could able to find the reason. please help me out my code is:

from sys import stdin,stdout
def prime_sieve( k, n ):
prime = [True for i in range( n + 1 )]
p = 2
while ( p * p <= n ):

  # If prime[p] is not changed, then it is a prime
  if (prime[p] == True):

     # Update all multiples of p
     for i in range( p * 2, n + 1, p ):
        prime[i] = False
  p += 1

for p in range( k, n+1 ):
if prime[p]:
stdout.write(str( p ))

if name == ‘main’:
t = int(stdin.readline())
for i in range(t):
p,n = stdin.readline().split()
prime_sieve(int( p ),int( n ))

This program is showing time limit exceeds. Please help me and thanks in advance.

  • created

    Mar '18
  • last reply

    Apr '18
  • 2

    replies

  • 892

    views

  • 2

    users

  • 1

    link

Is there any processing being repeated for each test case that could perhaps be performed only once?

No preprocessing is used in this program. I hope preprocessing help to resolve my issue i guess.