习题:Add Points (水题)

题目

传送门

思路

求个GCD就完事了

代码

#include<iostream>
#include<algorithm>
using namespace std;
int n;
int x[100005];
int g;
long long s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i];
	sort(x+1,x+n+1);
	g=x[2]-x[1];
	for(int i=3;i<=n;i++)
		g=__gcd(x[i]-x[i-1],g);
	for(int i=2;i<=n;i++)
		s=s+(x[i]-x[i-1]);
	cout<<s/g-(n-1);
	return 0;
}
posted @ 2020-02-08 12:04  loney_s  阅读(117)  评论(0)    收藏  举报