标签:
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1019
题目:
long gcd(long a,long b) { long r=1; while (r>0) { r=a%b; a=b; b=r; } return a;}
lcm(a,b)=a*b/gcd(a,b);
代码:
long lcm(long a,long b) { return a/gcd(a,b)*b; }
ac代码:
1 #include <iostream> 2 #include <algorithm> 3 #include <cstdio> 4 #include <cmath> 5 #include <cstring> 6 #include <queue> 7 #include <stack> 8 #include <map> 9 #include <vector> 10 11 #define PI acos((double)-1) 12 #define E exp(double(1)) 13 using namespace std; 14 15 long gcd(long a,long b) 16 { 17 18 long r=1; 19 while (r>0) 20 { 21 r=a%b; 22 a=b; 23 b=r; 24 } 25 return a; 26 // if(b) 27 // while( (a%=b) && (b %= a)); 28 // return a+b; 29 } 30 31 long lcm(long a,long b) 32 { 33 return a/gcd(a,b)*b; 34 } 35 int main (void) 36 { 37 int t,n; 38 cin>>t; 39 while(t--) 40 { 41 long temp,m; 42 cin>>n; 43 scanf("%ld",&temp); 44 for(int i = 1;i<n;i++) 45 { 46 scanf("%ld",&m); 47 temp = lcm(temp,m); 48 } 49 cout<<temp<<endl; 50 51 } 52 return 0; 53 }
标签:
原文地址:http://www.cnblogs.com/weeping/p/5351874.html