Integer roots: Difference between revisions

m
→‎{{header|Python}}: (applied pylint to formatting)
m (→‎{{header|Perl 6}}: generate initial guess numerically)
m (→‎{{header|Python}}: (applied pylint to formatting))
Line 660:
 
=={{header|Python}}==
<lang python>def root(a, b):
if b < 2:return b
a1=a-1 return b
ca1 = a - 1
c = 1
d=(a1*c+b//(c**a1))//a
ed = (a1 *d c + b // (dc ** a1)) // a
de = (a1 *c d + b // (cd ** a1)) // a
while c!=d and c!=e:
while c not in c,(d, e=d,e,(a1*e+b//(e**a1))//a:
c, d, e = d, e, (a1 * e + b // (e ** a1)) // a
return min(d, e)
print("First 2,001 digits of the square root of two:\n{}".format(root(2,2*100**2000)))</lang>
 
 
print("First 2,001 digits of the square root of two:\n{}".format(root(2,2*100**2000)))</lang>
root(2, 2 * 100 ** 2000)
))</lang>
 
{{out}}
9,655

edits