1 回答
TA贡献1835条经验 获得超7个赞
这可能是其中一种方法。
numbers=list(map(int,input().split()))
numbers.sort()
maximum=numbers[0] #gcd of the input numbers cannot be greater than minimum number in the list.Therefore we are retrieving the mininum number of the list.
gcd=1 #Initial value of gcd.
for i in range(1,(maximum+1)):
flag=0
for j in range(len(numbers)):
num=numbers[j]
if num % i ==0: #check if the every number in the input is divisible by the value of i
flag=1 #if divisible set flag=1 and then check the other numbers of the input.
else:
flag=0 #if any of the number of the input is not divisible then flag =0 and go to next iteration of i.
break
if flag==1:
gcd=i #if flag=1 that means every number of the input is divisible by the value of j.Update the value of gcd.
print(gcd)
可以通过以下方式完成:
for i in num_factors:
d={}
for j in i:
try:
d[j]=d[j]+1
except KeyError:
d[j]=1
dictionary_copy = d.copy()
a_list.append(dictionary_copy)
print(a_list)
return num_factors
添加回答
举报