sumMultiples() is a working general solution to Project Euler's first problem.  Don't read it if you want to try it yourself.  This question is about preserving this general nature while improving performance, perhaps using math tricks like sumSkip() and sumIndetity().  Unfortunately everything I find that takes advantage of these tricks sacrifices the ability to have a general solution that works with any number of multiples and any limit.  Notice how using sumSkip() and sumIdentity() require hand tuning to work.  I'd like to use the same interface sumMultiples() uses and allow any number of base numbers with any values.  Well, short of causing overflows anyway.In main sumSkip() and sumIdentity() are being used with the inclusionexclusion principle in a rigid hand tuned form.  I'm suspecting there is a general way to apply this principle to this problem but frankly I can't see it.  I'll accept solutions that don't use it so long as they truly improve this solutions Big O Complexity. I believe sumMultiples() is O(below x base) complexity.  I'm looking to improve on that.Before linking possible duplicates or solutions please ensure they deal with the general requirement.public static void main(String[] args) {    int below = 1000;    int[] base = {3, 5};    System.out.println( sumMultiples(below, base) );    // Making names shorter to help readability    int b0 = base[0];    int b1 = base[1];    // Hand tuned to number and values.  Something I'd like to avoid.    System.out.println( sumSkip(b0, below) + sumSkip(b1, below) - sumSkip(b0*b1, below) );    System.out.println(  b0*sumIdentity(below/b0) +                         b1*sumIdentity(below/b1-1) -                         b0*b1*sumIdentity( below / (b0*b1) )  );}// General solution - any sized base with any values - uses brute force approachprivate static int sumMultiples(int below, int... base) {    int result = 0;    boolean isMultiple;    // Every integer below limit    for(int i = 1; i < below; i++) {        // Resetting dirty bit pattern        isMultiple = false;        // Every base        for (int j = 0; j < base.length; j++) {            // Stays false until a multiple is found. Then stays true.            isMultiple |= i % base[j] == 0;        }        // Sum if i is a multiple of an integer in multiples        if (isMultiple) {            result += i;        }    }    return result;}// Skip non multiples - still fairly brute force - less generalpublic static int sumSkip(int base, int below) {    int result = 0;    int multiple = base;    while (multiple < below) {        result += multiple;        multiple += base;     }    return result;}// Sum using mathpublic static int sumIdentity(int n) {    return n*(n+1)/2;}Output:233168233168233168
General solution to sum multiples of multiple numbers below a limit
java;programming challenge;mathematics;comparative review