其他分享
首页 > 其他分享> > 8.10-Day1T1

8.10-Day1T1

作者:互联网

题目大意

裴蜀定理   题解 很简单... 我这个蒟蒻都猜的出来... 就求所有数的最大公约数 但注意 要加绝对值 因为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

 

   

 

标签:ch,Day1T1,long,int,while,include,8.10,getchar
来源: https://www.cnblogs.com/darlingroot/p/11345233.html