Skip to content

Instantly share code, notes, and snippets.

@oskar-j
Created July 31, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskar-j/3571dc48ec9e21814f42 to your computer and use it in GitHub Desktop.
Save oskar-j/3571dc48ec9e21814f42 to your computer and use it in GitHub Desktop.
Find perfect squares in a range of (A,B) in Python
import math
def solution(A, B):
bottom = int(math.ceil(math.sqrt(A)))
upper = int(math.floor(math.sqrt(B)))
# int should be enough
return upper - bottom + 1
print solution(4, 17) # should print 3
print solution(1000, 2000) # should print 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment