+ 2
Help me: Time limit exceed
Given 2 integers a and b. Find the last 2 digits of the number a^b Example: a = 3 and b = 6 --> lastTwoDigits(a, b) = "29" a = 7 and b = 4 --> lastTwoDigits(a, b) = "01" def lastTwoDigits(a,b): n=a b=b-1 a=str(a) if len(a)<2: a="0"+a elif len(a)>2: a=a[len(a)-2]+a[len(a)-1] else: a = a while b>0: b=b-1 a= "0"+str(int(a)*n) a=a[len(a)-2]+a[len(a)-1] return a
2 Respuestas
0
My algorithm is correct. But Time limit exceed, so Fail
0
Thank you so much :)