class Euler1 {
    public long calculate(long limit, long number){
        if (number > limit) return 0L;
        
        long count = limit / number;
        return number * (count + 1L) * count / 2L;
    }

    public long sum(long[] data, int index, long combination, long limit, int level){
        long result = 0L;
        if (combination == 1L);
        else{
            if ((level & 1L) == 1L)
                result += calculate(limit, combination);
            else
                result -= calculate(limit, combination);
        }

        if (level > data.length)
            return result;
        else{
            for (; index < data.length; index++)
                result += sum(data, index + 1, combination * data[index], limit, level + 1);
        }
        
        return result;
    }
    
    public static void main(String[] args) {
        Euler1 e = new Euler1();

        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L}, 0, 1L, 999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L}, 0, 1L, 9999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L}, 0, 1L, 99999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L}, 0, 1L, 999999999L, 0));

        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L}, 0, 1L, 999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L}, 0, 1L, 9999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L}, 0, 1L, 99999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L}, 0, 1L, 999999999L, 0));

        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L}, 0, 1L, 999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L}, 0, 1L, 9999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L}, 0, 1L, 99999999L, 0));
        System.out.println(e.sum(new long[]{2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L}, 0, 1L, 999999999L, 0));
    }
}