willsonlincake 发表于 2022-4-10 16:55:43

NumPy找最大公约数

import numpy as np

arr1 =
arr2 =

print ("arr1 : ", arr1)
print ("arr2 : ", arr2)

print ("\nGCD of arr1 and arr2 : ", np.gcd(arr1, arr2))
print ("\nGCD of arr1 and 10   : ", np.gcd(arr1, 10))

willsonlincake 发表于 2022-4-10 16:57:57

也可以用math.gcd()
import math

a = int(input("First number = "))
b = int(input("Second number = "))

print("GCD/HCF of", a, "and", b, "is", math.gcd(a,b))
print()
页: [1]
查看完整版本: NumPy找最大公约数