zoukankan      html  css  js  c++  java
  • HDU 1019

    入门题,好多数的 LCM

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 #define LL long long
     5 int t,n;
     6 LL a[100000000];
     7 LL ans;
     8 LL gcd(LL a,LL b)
     9 {
    10     if(a<b) swap(a,b);
    11     LL r=a%b;
    12     while(r)
    13     {
    14         a=b;
    15         b=r;
    16         r=a%b;
    17     }
    18     return b;
    19 }
    20 int main()
    21 {
    22     scanf("%d",&t);
    23     while(t--)
    24     {
    25         scanf("%d",&n);
    26         for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    27         if(n==1){
    28              printf("%lld
    ",a[1]); continue;
    29         }
    30         ans=a[1]*a[2]/gcd(a[1],a[2]);
    31         for(int i=3;i<=n;i++)
    32         {
    33             ans=ans*a[i]/gcd(ans,a[i]);
    34         }
    35         printf("%lld
    ",ans);
    36     }
    37 }//2016-04-22 17:12:29
    我自倾杯,君且随意
  • 相关阅读:
    sobel
    构造函数
    #pragma once & ifnde
    #pragma comment
    SET容器
    重载[] int& operator[ ]( )
    仿函数 operator()()
    remove_if erase
    vector
    map
  • 原文地址:https://www.cnblogs.com/nicetomeetu/p/5422090.html
Copyright © 2011-2022 走看看