public class Euler12 {
    static long divisorCount(long n) {
        if (n == 1)
            return 1;
        long count = 1;
        int exp = 0;
        while (n % 2 == 0) {
            n /= 2;
            exp++;
        }
        if (exp > 0)
            count *= (exp + 1);
        for (long p = 3; p * p <= n; p += 2) {
            exp = 0;
            while (n % p == 0) {
                n /= p;
                exp++;
            }
            if (exp > 0)
                count *= (exp + 1);
        }
        if (n > 1)
            count *= 2;
        return count;
    }

    static long solve(int minDivisors) {
        for (long n = 1;; n++) {
            long a = n, b = n + 1;
            if (a % 2 == 0)
                a /= 2;
            else
                b /= 2;
            if (divisorCount(a) * divisorCount(b) > minDivisors)
                return n * (n + 1) / 2;
        }
    }

    public static void main(String[] args) {
        assert solve(5) == 28 : "Checkpoint failed";
        System.out.println(solve(500));
    }
}
