Test instructions gives you a bunch of numbers and asks you to find them LMC (least common multiple). The first two are least common multiple equals they multiply and then one of their gcd (greatest common divisor), that three number of the largest common multiple how to ask? Obviously can't do as before, now give a theorem: If the number of least common multiple known n, then add a number of M, then this n+1 number of least common multiple equals the first n number of least common multiple and the newly added number m least common multiple. The problem that we need to solve now is only GCD left. How does the GCD beg?
GCD recursion theorem: For any nonnegative integer A and any positive integer B,GCD (A, b) = gcd (b, a mod b). GCD (b,a mod b) ==b can be easily found when a mod is b==0. So all I have to do is fix it.
#include <stdio.h>
#include <cstring>
#include <iostream>
using namespace Std;
int gcd (int a, int b)
{
Return (b==0) A:GCD (b,a%b);
}
int LCM (int a,int b)
{
Return A/GCD (A, b) *b;
}
int a[1000010];
int main ()
{
int t,n;
cin>>t;
while (t--)
{
cin>>n;
int lcm=1;
cin>>a[0];
LCM=A[0];
for (int i=1;i<n;i++)
{
cin>>a[i];
LCM=LCM (Lcm,a[i]);
}
cout<<lcm<<endl;;
}
return 0;
}
HDU 1019 (GCD and LMC)