1 solutions

  • 1
    @ 2025-1-8 18:38:08
    #include<bits/stdc++.h>
    using namespace std;
    int gcd(int a,int b) //最大公约数模型 
    {
    	if(b==0) return a;
    	return gcd(b,a%b);
    }
    int main()
    {
    	int n,last;
    	cin>>n>>last;
    	int res;
    	for(int i=1;i<=n;i++)
    	{
    		int t;
    		cin>>t;
    		int temp=abs(t-last);//计算差值 
    		if(i==1) //第一个空 
    		{
    			res=temp;
    		}
    		else//最大值和当前空求最大公约数 
    		{
    			res=gcd(res,temp);
    		}
    		last=t;
    	}
    	cout<<res;//最大公约数 
    	return 0;
    }
    
    • 1

    Information

    ID
    1806
    Time
    2000ms
    Memory
    1024MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    7
    Accepted
    4
    Uploaded By