Created
March 6, 2023 12:28
-
-
Save thinkphp/73a27d8a5e41c629c9303c0b2ad8c01b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hexaGCD( x, y, z): | |
def pow2(a,b): | |
p = 1 | |
for i in range(1,b+1): | |
p = p * a | |
return p | |
def val(c): | |
if ord(c) >= ord('0') and ord(c) <= ord('9'): | |
return ord(c) - ord('0') | |
elif ord(c) >= ord('A') and ord(c) <= ord('Z'): | |
return ord(c) - ord('A') + 10 | |
def conv(str): | |
n = len(str) | |
p = 0 | |
num = 0 | |
for i in range(n - 1, -1, -1): | |
num = num + val(str[i]) * pow2(16, p) | |
p += 1 | |
return num | |
def gcd(a,b): | |
while a!=b: | |
if a > b: | |
a = a - b | |
else: | |
b = b - a | |
return a | |
GreatestCommonDivisor = gcd(conv(x),conv(y)) | |
GreatestCommonDivisor = gcd(GreatestCommonDivisor, conv(z)) | |
return GreatestCommonDivisor | |
print(hexaGCD("AA","BB","CC")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment