Created
January 12, 2011 15:29
-
-
Save nitinhayaran/776298 to your computer and use it in GitHub Desktop.
Solution for Double Square Problem in Facebook Hacker Cup Qualification Round
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
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