Created
January 12, 2011 03:01
-
-
Save mallyvai/775620 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Qual Round Problem #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt, floor, ceil | |
def compute(num): | |
upper_bound = int(ceil(sqrt(num))) | |
counter = 0 | |
lower_bound = int(sqrt(floor(num/2))) | |
for i in range(lower_bound, upper_bound+1): | |
diff = num - i**2 | |
if diff < 0: | |
continue | |
s = sqrt(diff) | |
if s == int(s): | |
counter += 1 | |
return counter | |
lines = open("input.txt").readlines() | |
print(lines) | |
fh = open("temp.txt", 'w') | |
for line in lines[1:]: | |
fh.write(str(compute(int(line.strip())))+"\n") | |
fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment