hdu1019 Least Common Multiple

题目链接: hdu1019 ( Least Common Multiple )

求解最小公倍数: \(lcm(a,b)=a/gcd(a,b)*b\) .

/**
 * hdu1019 Least Common Multiple
 *
 */

#include <cstdio>

int gcd(int a, int b)
{
    while (b) {
        int t = a%b;
        a = b;
        b = t;
    }
    return a;
}

int main()
{
    int T;
    scanf("%d", &T);
    while (T--) {
        int m;
        scanf("%d", &m);
        int res = 1;
        while (m--) {
            int x;
            scanf("%d", &x);
            res = res/gcd(res,x)*x;
        }
        printf("%d\n", res);
    }
    return 0;
}

gcd模板

typedef long long LL;
LL gcd(LL a, LL b)
{
    while (b) {
        LL t = a%b;
        a = b;
        b = t;
    }
    return a;
}
上一篇:CentOS8访问windows共享文件夹,挂载windows共享文件夹


下一篇:轻蜗牛直租平台-common-utils工具类简介