Project Euler #5: Smallest multiple

  • + 0 comments

    Python 3:

    #!/bin/python3
    
    import sys
    
    def findGCD(a,b):
        while b!=0:
            remainder = a%b
            a=b
            b=remainder
            
        return a
        
    def lcmUsingGCD(a,b):
        return abs(a*b)//findGCD(a,b)
        
    def numLCM(n):
        lcm=1
        for i in range(2, n+1):
            lcm = lcmUsingGCD(lcm, i)
        print(lcm)
    
    t = int(input().strip())
    for a0 in range(t):
        n = int(input().strip())
        numLCM(n)