• hud 1019最小公倍数


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019

    思路:头两个数先求,再用所求的数与后面的一个数求,依次类推

     1 #include<stdlib.h>
     2 #include<time.h>
     3 #include <cstdio>  
     4 #include <cstring>  
     5 #include <cmath>  
     6 #include <cstdlib>  
     7 #include <ctime>  
     8 #include <iostream>  
     9 #include <algorithm>  
    10 #include <vector>  
    11 #include <queue>  
    12 #include <map>  
    13 #include <set>  
    14 #include <string.h>  
    15 using namespace std;
    16 
    17 int n,m;
    18 int arr[1000];
    19 
    20 int gcd(int a,int b)
    21 {
    22     if(b)
    23         return gcd(b,a%b);
    24     else
    25         return a;
    26 }
    27 
    28 int lcm(int a,int b)
    29 {
    30     return a/gcd(a,b)*b;  //此处不能用a*b/gcd(a,b)数据会溢出 
    31 }
    32 
    33 int main()
    34 {
    35     while(scanf("%d",&n)!=EOF)
    36     {
    37         while(n--)
    38         {
    39             scanf("%d",&m);
    40             int t;
    41             scanf("%d",&t);
    42             for(int i=1;i<=m-1;i++)
    43             {
    44                 scanf("%d",&arr[i]);
    45                 t=lcm(t,arr[i]);
    46             }
    47             printf("%d
    ",t);
    48             
    49         }
    50     } 
    51     return 0;
    52  } 
  • 相关阅读:
    Django搭建环境
    python切片
    python数据类型
    jquery 淡入淡出属性
    Jquery Tab切换
    jQuery Clone方法
    jQuery属性操作
    python 变量以及循环
    获取网站目录
    posting-jsonobject-with-httpclient-from-web-api
  • 原文地址:https://www.cnblogs.com/pter/p/4979165.html
Copyright © 2020-2023  润新知