# How to speed up Python code?

Help speed up code:
``````a=int(input())
b=1
def koren(a,b):
while b*b<=a:
b+=1
if b*b==a:
print(b)
else:
print(b-1)
koren(a,b)``````

https://acmp.ru/index.asp?main=task&id_task=146
Link tasks
April 7th 20 at 10:47
3 answers
April 7th 20 at 10:49
``````def duren(a):
lo, hi = 1 if a else 0, a
while lo + 1 < hi:
mid = (lo + hi) // 2
if mid * mid > a:
hi = mid
else:
lo = mid
print(lo)

duren(123456789 ** 2)``````
April 7th 20 at 10:51
import time #current time
NOW_TIME=(time.time()) #record the start time

from math import sqrt,floor #root, rounding down

f_in=open('INPUT.TXT','r') #open for reading INPUT.TXT
A=int(f_in.read()) #converting str to int if there natural then the exception will not give
f_in.close() #close INPUT.TXT
B=floor(sqrt(A)) #calculated the root of A, rounded downwards
f_out=open('OUTPUT.TXT','w')#open for write OUTPUT.TXT
f_out.write(str(B)) #translate the number in str and write it to the OUTPUT.TXT
f_out.close() #close OUTPUT.TXT

NEXT_TIME=time.time()#record the last time

#print values
print(NOW_TIME)
print(NEXT_TIME)
print(A)
print(B)
You have non-working code)is Missing casts and one brace)) - holly.Howe commented on April 7th 20 at 10:54
@jamal.Bashirian47: Read the full problem statement from the review's author and try to repeat the original number equal to 10**3000 ;) - christina_Oberbrunner33 commented on April 7th 20 at 10:57
April 7th 20 at 10:53
``````from math import floor
from decimal import *

getcontext().prec = 1500
print(floor(Decimal(input()).sqrt()))``````
Thank you very much! Help! - ruthe_Nicolas79 commented on April 7th 20 at 10:56

Find more questions by tags Python