OpenJudge - 01001:Exponentiation
这道题主要考察高精度计算,由于使用python,这里使用库,个人使用的时候通常直接写出以下代码之后大致正常处理:
from decimal import Decimal, getcontext, MAX_PREC
getcontext().prec = MAX_PREC
这里的MAX_PREC相当于直接使用了最高的精度,之后处理的时候就无需担心精度的问题了。
代码很短(说明这个库用起来很方便):
from decimal import Decimal, getcontext, MAX_PREC
getcontext().prec = MAX_PREC
while True:
try:
R, n = input().split()
ans = (Decimal(R)**int(n)).normalize()
ans = '{:f}'.format(ans)
if ans[:2] == '0.':
ans = ans[1:]
print(ans)
except EOFError:
break
这是我的第一篇博客,欢迎大家批评指正!谢谢!