Created
September 19, 2011 15:08
-
-
Save vigneshsarma/1226711 to your computer and use it in GitHub Desktop.
Double Squre
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 math | |
def isSuperSqure(n): | |
hlf=int(math.sqrt(n)) | |
start=0 | |
count=0 | |
while(hlf>=start): | |
if((start+hlf)<=n): | |
no=(start**2)+(hlf**2) | |
if(no>n): | |
hlf-=1 | |
elif(no | |
start+=1 | |
else: | |
count+=1 | |
print hlf,start,count | |
hlf-=1 | |
start+=1 | |
return count | |
if __name__ == "__main__": | |
f=open("double_squares.txt",'r') | |
limit=int(f.readline()) | |
fr=open("out1.txt",'w') | |
while(limit>0): | |
n=int(f.readline()) | |
limit-=1 | |
fr.write(str(isSuperSqure(n))+'\n') | |
fr.close() | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Facebook Hackers-cup Double square solution