/BaseSqrtRem.py Secret
Created
May 1, 2018 14:38
BaseSqrtRem - base case for the Karatsuba Square Root algorithm
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
def BaseSqrtRem(m): | |
if m>999 or m<1: | |
print "Errore nella chiamata a BaseSqrtRem" | |
return (0,0) | |
# elenco i quadrati minori di 1000 | |
d = { | |
0 : 0, | |
1 : 1, | |
4 : 2, | |
9 : 3, | |
16 : 4, | |
25 : 5, | |
36 : 6, | |
49 : 7, | |
64 : 8, | |
81 : 9, | |
100 : 10, | |
121 : 11, | |
144 : 12, | |
169 : 13, | |
196 : 14, | |
225 : 15, | |
256 : 16, | |
289 : 17, | |
324 : 18, | |
361 : 19, | |
400 : 20, | |
441 : 21, | |
484 : 22, | |
529 : 23, | |
576 : 24, | |
625 : 25, | |
676 : 26, | |
729 : 27, | |
784 : 28, | |
841 : 29, | |
900 : 30, | |
961 : 31, | |
1024 : 32} | |
k=0 | |
for i in sorted(d): | |
if i>m: | |
break | |
k=i | |
s = d[k] | |
r = m - s*s | |
return (s,r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment