题目:
思路:
1、给数组排序,求出两两之间的差值即公差,如果差值为0,直接返回n,否则进入第二步;
2、给差值数组排序,求出两两之间的最大公因数即公差
代码:
def gcd(x, y):while y:x, y = y, x%yreturn x
n = int(input())
a = list(map(int, input().split()))
a.sort()
s = []
k = max(a)-min(a)
for i in range(n-1):s.append(a[i+1]-a[i])
s.sort()
d = min(s)
if d == 0:res = n
else:d = gcd(s[0],s[1])for i in range(3, len(s)):d = gcd(d,s[i])res = k//d+1
print(res)