最小公倍数
“辗转相除法”求解最小公倍数
Function LCM(ParamArray nums()) As Long
Dim temp1 As Long, temp2 As Long, I As Long
LCM = nums(0)
For I = 1 To UBound(nums)
temp1 = LCM
temp2 = nums(I)
LCM = LCM * temp2
Do
           If temp1 < temp2 Then
            temp = temp1
            temp1 = temp2
           temp2 = temp
        End If
       temp1 = temp1 Mod temp2
    Loop While temp1
LCM = LCM / temp2
Next
End Function
'调用:
MsgBox LCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
   
 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号