Python 90分求调

P2293 [HNOI2004] 高精度开根

@[TLEWA](/user/515129) 精度问题,若是3次方根他就很头疼
by da_ke @ 2024-03-31 14:59:52


@[TLEWA](/user/515129) ```python from decimal import * getcontext().prec = 5000 def qp(a,b): ans=Decimal(1) base=Decimal(a) while(b!=0): if(b%2==1): ans*=base base*=base b//=2 return ans a=Decimal(input()) b=Decimal(input()) l=Decimal(0) r=Decimal(1) while(1): if(qp(r,a)>b): break l=r r*=2 while l+1<r: mid=(l+r)//2 if (qp(mid,a)<=b) : l=mid else: r=mid if (qp(l,a)<=b): print(l) else: print(r) ```
by da_ke @ 2024-03-31 15:01:17


|