[蓝桥杯] 等差数列 (Python 实现)
作者:互联网
题目:
代码:
def gcd (a, b):
return gcd(b, a % b) if b else a
n = int(input())
nums = list(map(int,input().split(' ')))
nums.sort()
diff = [nums[i] - nums[i-1] for i in range(1,n)]
temp = gcd(diff[0],diff[1])
for x in range(2,len(diff)):
temp = gcd(temp, diff[x])
try:
print(((nums[-1] - nums[0])//temp) + 1)
except:
print(len(nums))
标签:gcd,temp,nums,Python,蓝桥,int,print,diff,等差数列 来源: https://blog.csdn.net/d_l_w_d_l_w/article/details/122470860