HDU 1019 Least Common Multiple

多个数的最小公倍数

数的类型不能为int ,而是选择long long 类型

若是使用scanf, printf函数时 用%I64d,而不是%lld ,即使两种实质意义没什么不同,仅仅是平台不一样

最小公倍数可以用辗转相除法,这里没有用,简单

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int Common(int a, int b) {
 6     int t = (a < b )? a : b;
 7     while(t > 0) {
 8         if(a % t == 0 && b % t == 0)
 9             break;
10         t --;
11     }
12     return t;
13 }
14 
15 int main()
16 {
17 
18     freopen("C:\Users\super\Documents\CB_codes\in.txt", "r", stdin);
19     //freopen("C:\Users\super\Documents\CB_codes\out.txt","w",stdout);
20     int T, n;
21     long long int a, b;
22     scanf("%d", &T);
23     while(T --) {
24         scanf("%d", &n);
25         b = 1;
26         for(int i = 0; i < n; i ++) {
27             scanf("%I64d", &a);
28             b = b * a / Common(a, b);
29         }
30 
31         printf("%I64d
", b);
32     }
33 
34 
35     fclose(stdin);
36     return 0;
37 }
---------------- 人们生成的最美好的岁月其实就是最痛苦的时候,只是事后回忆起来的时候才那么幸福。
原文地址:https://www.cnblogs.com/livelihao/p/5294866.html