【发布时间】:2020-05-05 06:41:18
【问题描述】:
我正在尝试在 SPOJ https://www.spoj.com/problems/LASTDIG/ 上解决此问题,我确信代码是正确的,但是当我在它显示的网站上提交它时,超出了时间限制,
问题的解决代码是:
t=int(input()) #for test cases
for i in range(0,t):
x,y=input().split() #for two seperate input
a=int(x)
b=int(y)
if 0<=a<=20 and 0<=b<=2147483000: #conditions for input
z=x**y
c=str(z)
print(c[-1]) #finally to print the last digit of the number
我怀疑可能是程序太简单了,较大的输入需要时间?那么,任何人都可以建议如何改进解决方案,还是我需要选择其他语言,如 C++?
【问题讨论】:
标签: python python-3.x array-algorithms