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\n",t);
48             
49         }
50     } 
51     return 0;
52  } 

 

转载于:https://www.cnblogs.com/pter/p/4979165.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值