Skip to content

Instantly share code, notes, and snippets.

@nitinhayaran
Created January 12, 2011 15:29
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 nitinhayaran/776298 to your computer and use it in GitHub Desktop.
Save nitinhayaran/776298 to your computer and use it in GitHub Desktop.
Solution for Double Square Problem in Facebook Hacker Cup Qualification Round
import sys
from math import sqrt
def main(filename):
inputf = open(filename,'rU')
totalLines = inputf.readlines()
totalLines.pop(0)
for i in totalLines:
count = 0
valuesArr = []
for x in range(int(sqrt(int(i)))+1):
y = sqrt(int(i) - x*x)
if y == int(y):
if x*x == y:
count += 2
else:
count += 1
print str(count/2)
inputf.close()
if __name__ == '__main__':
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment