题解:P15032 [UOI 2021 II Stage] 棋子
LiuHongshen · · 题解
P15032 [UOI 2021 II Stage] 棋子 题解
题目传送门
题目描述
近日,哥萨克胡子发现了一枚棋子以及位于同一条直线上的
哥萨克胡子可以首先选择任意一个正整数
哥萨克胡子想知道:在
输入格式
第一行包含两个整数
第二行包含
输出格式
输出一个数字 —— 棋子能够访问所有
做法分析
棋子能到
要让所有点到达,需满足
代码
#include<bits/stdc++.h>
#define endl '\n'
#define kuaitou ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define baoliu(n) fixed<<setprecision(n)
#define int long long
using namespace std;
signed main(){
kuaitou;
int n,x;//定义变量
cin>>n>>x;//输入
int a[n+1]={};//定义数组
int ans=0;//定义答案
for(int i=1;i<=n;i++){//遍历数组
cin>>a[i];//输入
ans=__gcd(ans,abs(a[i]-x));//是ans是最大公因数
}
cout<<ans;//输出
return 0;//完结散花
}
AC记录