1. 程式人生 > >洛谷P4549裴蜀定理

洛谷P4549裴蜀定理

傳送門

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#define re register
using namespace std;

inline int read(){
    char ch = getchar();
    int f = 1 , x = 0 ;
    while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + ch - '0'; ch = getchar();}
    return x * f;
}

int n,x[25];
int ans;

inline int gcd(int a , int b) {
    if(b == 0)  return a;
    return gcd(b , a % b);
}

int main(){
    n = read(); 
    for(re int i = 1 ; i <= n ; ++i)  x[i] = read();
    for(re int i = 1 ; i <= n ; ++i) {
        if(x[i] < 0) x[i] = -x[i];
        ans = gcd(ans , x[i]);
    }
    printf("%d\n",ans);
    return 0;
}