We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85fd9cc commit d2e7501Copy full SHA for d2e7501
Unit Digit of a raised to power b.py
@@ -0,0 +1,11 @@
1
+def last_digit(a, b):
2
+ if b==0: #This Code assumes that 0^0 is 1
3
+ return 1
4
+ elif a%10 in [0,5,6,1]:
5
+ return a%10
6
+ elif b%4==0:
7
+ return ((a%10)**4)%10
8
+ else:
9
+ return ((a%10)**(b%4))%10
10
+
11
+#Courtesy to https://brilliant.org/wiki/finding-the-last-digit-of-a-power/
0 commit comments