Acm hdu 1019 least common multiple

Source: Internet
Author: User
Least common multiple

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 11716 accepted submission (s): 4278

Problem descriptionthe least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. for example, the LCM of 5, 7 and 15 is 105.

Inputinput will consist of multiple problem instances. the first line of the input will contain in a single integer indicating the number of problem instances. each instance will consist of a single line of the Form M N1 N2 N3... NM where M is the number of integers in the set and N1... nm are the integers. all integers will be positive and lie within the range of a 32-bit integer.

Outputfor each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.

Sample input2
3 5 7 15
6 4 10296 936 1287 792 1

Sample output105
10296

Sourceeast central North America 2003, practice

Recommendjgshining
`# Include  <  Stdio. h  >    Int  Gcd (  Int  A,  Int  B){  If  (B  =  0  )  Return  A; Return  Gcd (B,  %  B );}  Int  Main (){  Int  T;  Int  N, A, B, I;  Int  CNT;Scanf (  "  % U  "  ,  & T );  While  (T  --  ){Scanf (  "  % D  "  ,  &  N );CNT  =  A  =  1  ;  For (I  =  1  ; I  <=  N; I  ++  ){Scanf (  "  % D  "  ,  &  B );CNT  =  A  / Gcd (A, B)  *  B;  //  Next, remove and multiply to avoid data overflow.    A  =  CNT;}Printf (  "  % D \ n  "  , CNT );}  Return     0 ;< BR >}`
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.