标签:cout end log return i++ 递归 ios mon comm
#include<iostream> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a%b); } int lcm(int a, int b) { return a / gcd(a, b)*b;//先除再乘,减少溢出 } int main() { int n; int m; int number1, number2; cin >> n; while (n--) { cin >> m; cin >> number1;//写的好处,省去用数组 for (int i = 1; i < m; i++)//第一数,先输入了所以i从1开始 { cin >> number2; number1 = lcm(number1, number2);//隐藏的递归,妙! } cout << number1 << endl; } return 0; }
Codeup2136 HDU1019 Least Common Multiple
标签:cout end log return i++ 递归 ios mon comm
原文地址:http://www.cnblogs.com/dusanlang/p/7473190.html