【BZOJ】1441 Min(数学)

题目

传送门:QWQ

 

 

分析

 

裴蜀定理。

因为存在 $ a_1 $ $ a_2 $...... $ a_n $的最大公约数为 $ d $,那么必定存在 $ x_1*a_1+x_2*a_2+...x_n*a_n=d $

然后就A了。

 

 

代码

/**************************************************************
    Problem: 1441
    User: noble_
    Language: C++
    Result: Accepted
    Time:4 ms
    Memory:1288 kb
****************************************************************/
 
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
 
int getint()
{
    int x; scanf("%d",&x); return x;
}
int main()
{
    int n, x;
    scanf("%d",&n);
    int ans=getint();
    for(int i=1;i<n;i++)
    {
        ans=gcd(ans,abs(getint()));
    }
    printf("%d",ans);
    return 0;
}
View Code

 

posted @ 2018-02-12 17:15  noble_(noblex)  阅读(112)  评论(0编辑  收藏  举报
/* */