[BZOJ1441]Min:Bezout定理

分析:

答案显然是gcd(abs(ai))。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>

typedef long long LL;
int n;

inline LL Gcd(LL x,LL y){
        if(!x||!y) return x+y;
    while(y){
        std::swap(x,y);
        y%=x;
    }
    return x;
}

int main(){
    LL ans;
    scanf("%d%lld",&n,&ans);
    for(int i=2;i<=n;i++){
        LL x;scanf("%lld",&x);
        if(x) ans=Gcd(ans,abs(x));
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/ErkkiErkko/p/9649613.html