5 / 5
Jun 2016

this code is working fine in any other compiler but but when i click on submit it shows time limit exceeded what i can i do to make it more smaller?? help!
"less than creting problem with pre tag so it look a little bit nasty but in actual it is i less than t"

t=input("")
i=0
while i

<

  t:
    min,max=map(int,raw_input().split())
    for a in range(min,max+1):
        count=0
        for b in range(2,a/2):
            if (a%b)==0:
                count=1
                break
        if count==0 and a!=1 and a!=4:
            print(a)
    print
    i+=1
  • created

    Jun '16
  • last reply

    Jun '16
  • 4

    replies

  • 1.7k

    views

  • 2

    users

  • 1

    like

  • 2

    links

Your code does not compile.Which test cases did you check? What do you think is the worst case for your code?Think about the operations your code performs for numbers near 10**9. Not all of them are necessary

it was working fine for the small values but whenever i enter the value near to 10**9 my system get freeze and i am unable to do anything further so can u plz tell me how to correct it.

When trying to search for primes the key is to know what you do not need to check or calculate. Examples: Can you skip numbers because you know they cannot be prime? What is the biggest possible divisor of a number? Do you have to run through all divisor candidates?There is a lot of information on prime search in the internet. And e.g. the good old sieve of Eratosthenes is fully ok here.