杭电1019Least Common Multiple
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1019
解题思路:
Talk is cheap. Show me the code.
没有技巧全是感情
1 #include<bits/stdc++.h>//hduoj1019lcm 2 using namespace std; 3 int a[1010]; 4 int lcm(int a,int b) 5 { 6 return a/__gcd(a,b)*b; 7 } 8 int main() 9 { 10 std::ios::sync_with_stdio(false); 11 int t; 12 cin>>t; 13 while(t--) 14 { 15 int n; 16 cin>>n; 17 for(register int i=1;i<=n;i++) 18 cin>>a[i]; 19 int ans=a[1]; 20 for(register int i=2;i<=n;i++) 21 ans=lcm(ans,a[i]); 22 cout<<ans<<endl; 23 } 24 return 0; 25 }
本文来自博客园,作者:江上舟摇,转载请注明原文链接:https://www.cnblogs.com/LQS-blog/p/16221127.html