zoukankan      html  css  js  c++  java
  • HDU 1019

    题目:HDU1019  Least Common Multiple

    题目分析:就是最小公倍数和最大公约数的求解。

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int a[1005];
    
    int GCD(int a, int b)
    {
     int temp;
     if (a<b)
     {
      temp=a;
      a=b;
      b=temp;
     }
     if (b==0)
      {
       return a;
      }
      else
       {
        return GCD(b,a%b);
       }
    }
    
    
    int LCM(int a, int b)
    {
     return (a*(b/GCD(a,b)));
    }
    
    
    int main()
    {
     int i,times,numbers,results;
     cin>>times;
     while (times--)
      {
       cin>>numbers;
       for (i=0;i<numbers;i++)
        {
         scanf("%d",&a[i]);
        }
        if (numbers==1)
        {
         cout<<a[0]<<endl;
        }
        else
        {
        results=LCM(a[0],a[1]);
        for (i=2;i<numbers;i++)
         {
          results=LCM(results,a[i]);
         }
       cout<<results<<endl;
      }
    }
      return 0;
    }
    技进乎艺,艺进乎道
  • 相关阅读:
    USB
    Google
    机型参数
    mac
    反编译
    xcode
    Ios 消息推送
    真机:特殊
    Android
    object-c
  • 原文地址:https://www.cnblogs.com/weekend/p/5497721.html
Copyright © 2011-2022 走看看