1 solutions

  • 0
    @ 2023-12-6 11:12:15

    使用c++的库函数__gcd最大公约数。

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n;
    	cin >> n;
    	int a[100005] , b[100005];
    	for(int i = 0; i < n ;i++){
    		cin >> a[i];
    	}
    	sort(a , a + n);
    	int zong = a[n-1] - a[0];
    	int d = a[1];
    	for(int i = 1 ;i < n ;i++){
    		b[i] = a[i] - a[i - 1];
    	}
    	d = __gcd(b[1] , b[2]);
    	for(int i = 3 ;i < n ;i++){
    		d = __gcd(d , b[i]);
    	}
    	int num = zong/d;
    	cout << num + 1;
    	return 0;
    }
    
    • 1

    Information

    ID
    6475
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    88
    Accepted
    17
    Uploaded By