• <input id="auww4"></input>
  • <input id="auww4"><acronym id="auww4"></acronym></input>
  • <input id="auww4"><u id="auww4"></u></input>
    <object id="auww4"><acronym id="auww4"></acronym></object>
    <menu id="auww4"></menu><input id="auww4"><u id="auww4"></u></input>
    <input id="auww4"><u id="auww4"></u></input>
  • F.A.Q
    Hand In Hand
    Online Acmers
    Forum | Discuss
    Statistical Charts
    Problem Archive
    Realtime Judge Status
    Authors Ranklist
     
         C/C++/Java Exams     
    ACM Steps
    Go to Job
    Contest LiveCast
    ICPC@China
    Best Coder beta
    VIP | STD Contests
    Virtual Contests
        DIY | Web-DIY beta
    Recent Contests
    Author ID 
    Password 
     Register new ID

    lcm,gcd水題,注意n=1的情況

    Posted by 1904010229 at 2020-10-07 22:33:57 on Problem 1019
    (0)  


    AC代碼:
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e4+5;
    #define ll long long
    long long n,a[maxn],t;
    ll gcd(ll a,ll b){
      return b==0?a:gcd(b,a%b);
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        long long ans;
        cin>>t;
        while(t--){
            cin>>n;
            for(int i=1;i<=n;i++) cin>>a[i];
            if(n==1){cout<<a[1]<<endl; continue;}
            ans=a[1]/gcd(a[1],a[2])*a[2];
            for(int i=3;i<=n;i++) ans=ans/gcd(ans,a[i])*a[i];
            cout<<ans<<endl;
        }
        return 0;
    }

    Followed by:


    Post your reply here:

    Author ID
    Password
    Title
    Content  
     
    Hangzhou Dianzi University Online Judge 3.0
    Copyright © 2005-2020 HDU ACM Team. All Rights Reserved.
    Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
    Total 0.000000(s) query 5, Server time : 2020-10-14 09:20:32, Gzip enabled
    棋牌