題目的意思就是找n個數的最小公倍數,可以通過短除法來做,也可以直接從最大的數一直加一開始找
/*
*
*Problem Description
*求n個數的最小公倍數。
*
*
*Input
*輸入包含多個測試實例,每個測試實例的開始是一個正整數n,然後是n個正整數。
*
*
*Output
*爲每組測試數據輸出它們的最小公倍數,每個測試實例的輸出佔一行。你可以假設最後的輸出是一個32位的整數。
*
*
*Sample Input
*2 4 6
*3 2 5 7
*
*
*Sample Output
*12
*70
*
*
*Author
*lcy
*
*
*Source
*C語言程序設計練習(五)
*
*
*Recommend
*lcy
*
*/
#include<iostream>
using namespace std;
int main() {
int n, max, *a, result, cnt;
while (cin >> n) {
max = 0;
result = 1;
a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (max < a[i]) max = a[i];
}
max--;
do {
max++;
cnt = 0;
for (int i = 0; i < n; i++) {
if (max%a[i] == 0) {
cnt++;
}
}
} while (cnt != n);
cout << max << endl;
}
system("pause");
return 0;
}