title: How to find perfect squares in a range efficiently when the inputs are large numbers in Python
body: <p>The question is how to find perfect squares in a given range efficiently when the inputs are very large numbers. My solution is giving <code>Time Limit Exceeded</code> error. I have already checked the following links, but they didn't solve my problem:<br>
  - <a href="https://stackoverflow.com/questions/17508859/python-program-on-perfect-squares">Python Program on Perfect Squares</a><br>
  - <a href="https://stackoverflow.com/questions/2489435/how-could-i-check-if-a-number-is-a-perfect-square">How could I check if a number is a perfect square?</a><br>
  - <a href="https://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer">Fastest way to determine if an integer&#39;s square root is an integer</a> (I have no idea how to implement the solution given in this link in Python).</p>
  
  <p>The problem question is:</p>
  
  <blockquote>
    <p>Input Format: First line contains T, the number of testcases. T test cases follow, each in a newline.  Each testcase contains two space separated integers denoting A and B. Find all the perfect squares in the range A and B (both inclusive).</p>
  </blockquote>
  
  <p>Example of an input:</p>
  
  <pre>
  2
  3 9
  17 24
  </pre>
  
  <p>The code I wrote is:</p>
  
  <pre><code>import math
  def is_perfect_square(n):
      return n % n**0.5 == 0
  
  t = int(raw_input())
  for i in range(t):
      numbers = map(int, raw_input().split())
      count = 0
      for j in xrange(numbers[0], numbers[1] + 1): # I also tried range() which gave memory error
          if (is_perfect_square(j)):
              count = count + 1
  
      print count
  </code></pre>
  
  <p>While this code is working for smaller numbers, it is giving <code>Time limit exceeded</code> error for large inputs.</p>
  
  <p>(NOTE : <code>gmpy</code> is not an option as the code has to be run on an online compiler which does not have the <code>gmpy</code> module)</p>