GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python/maths/binary_exponentiation.py at master · dwsandy30/Python Expand file tree/ Copy pathbinary_exponentiation.pyMore file actions 28 lines (19 loc) · 600 Bytes / Copy pathbinary_exponentiation.pyFile metadata and controls28 lines (19 loc) · 600 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 """Binary Exponentiation.""" # Author : Junth Basnet # Time Complexity : O(logn) def binary_exponentiation(a, n): if n == 0: return 1 elif n % 2 == 1: return binary_exponentiation(a, n - 1) * a else: b = binary_exponentiation(a, n / 2) return b * b if __name__ == "__main__": try: BASE = int(input("Enter Base : ").strip()) POWER = int(input("Enter Power : ").strip()) except ValueError: print("Invalid literal for integer") RESULT = binary_exponentiation(BASE, POWER) print(f"{BASE}^({POWER}) : {RESULT}") |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |