smallest number divisible by all numbers from 1 to 20? Project Euler question 5
The most optimal solution would be to calculate the LCM of 1 to 20 directly using the standard Euclidean algorithm.

// calculate GCD using Euclidean algorithm
public long GCD(long a, long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

// calculate LCM using simple formula based on GCD
public long LCM(long a, long b) {
    var gcd = GCD(a, b);
    return a * b / gcd;
}

// iteratively calculate LCM of 1 through 20
public static void Main(string args[]) {
    long result = 1;

    // loop through each value 1 to 20, and LCM with previous result
    for (long n = 2; n &lt;= 20; n++) {
        result = LCM(result, n);
    }

    // print out the result
    Console.WriteLine(result);
}


In terms of complexity, this algorithm is roughly O(n) for small n.