8.10-Day2T1最小值

题目大意

裴蜀定理
 
题解
很简单...
我这个蒟蒻都猜的出来...
就求所有数的最大公约数
但注意
要加绝对值
因为gcd里面不能传负数
 
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
inline int read()
{
    int sum = 0,p = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')
            p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        (sum *= 10) += ch - '0';
        ch = getchar();
    }
    return sum * p;
}

ll gcd(ll a,ll b)
{
    if(b == 0)
        return a;
    else
        return gcd(b,a % b);
}

int main()
{
    freopen("min.in","r",stdin);
    freopen("min.out","w",stdout); 
    int n = read();
    ll a = read(),b;
    a = abs(a);
    for(int i = 2;i <= n;i++)
    {
        b = read();
        b = abs(b);
        a = gcd(a,b);
    }
    printf("%lld",a);
    return 0;
}
View Code

 

 
 

 

posted @ 2019-08-13 12:51  darrrr  阅读(57)  评论(0编辑  收藏  举报