zoukankan      html  css  js  c++  java
  • 【HDU 2028】Lowest Common Multiple Plus

    Problem Description


    求n个数的最小公倍数。

    Input


    输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。

    Output


    为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。

    Sample Input

    2 4 6
    3 2 5 7
    

    Sample Output

    12
    70
    
    #include <bits/stdc++.h>
    #define ll long long
    #define inf 1000000000
    #define PI acos(-1)
    #define bug puts("here")
    #define REP(i,x,n) for(int i=x;i<=n;i++)
    #define DEP(i,n,x) for(int i=n;i>=x;i--)
    #define mem(a,x) memset(a,x,sizeof(a))
    typedef unsigned long long ull;
    using namespace std;
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void Out(int a){
        if(a<0) putchar('-'),a=-a;
        if(a>=10) Out(a/10);
        putchar(a%10+'0');
    }
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    int main(){
        int n;
        while(cin>>n){
            ll tmp=read(),x,y=tmp;
            REP(i,2,n){
                x=read();
                y=y/gcd(tmp,x)*x;
                tmp=y;
            }
            printf("%lld
    ",tmp);
        }
        return 0;
    }
    
    
  • 相关阅读:
    dom操作
    今天学到的知识点
    3.26随笔
    dom操作
    Ajax
    JSP、EL、JSTL
    Cookie和Session
    HttpServletResponse
    Servlet
    tomcat
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/7627034.html
Copyright © 2011-2022 走看看