import java.util.*;

public class Euler341 {

    static int[] precomputeGolombUntil(long maxQueryPosition) {
        int[] golomb = new int[11000000];
        golomb[0] = 0;
        golomb[1] = 1;
        int size = 2;

        long products = 1;
        int i = 2;

        while (products < maxQueryPosition) {
            int prev = i - 1;
            int g_prev = golomb[prev];
            int nested = golomb[g_prev];
            int idx = i - nested;
            int current = 1 + golomb[idx];

            if (size == golomb.length) {
                golomb = Arrays.copyOf(golomb, golomb.length * 2);
            }
            golomb[size++] = current;
            products += (long) i * current;
            i++;
        }

        return Arrays.copyOf(golomb, size);
    }

    static class QueryState {
        long index = 1;
        long sum = 1;
        long products = 1;
        long prev_sum = 0;
        long prev_products = 0;
    }

    static long golombAt(long x, int[] golomb, QueryState st) {
        while (st.products < x) {
            st.index++;
            st.prev_sum = st.sum;
            st.prev_products = st.products;

            int g = golomb[(int) st.index];
            st.sum += g;
            st.products += st.index * g;
        }

        long spanIndex = st.index;
        long offset = (x - st.prev_products + spanIndex - 1) / spanIndex;
        return st.prev_sum + offset;
    }

    static long sumGolombCubes(long limit, int[] golomb) {
        QueryState st = new QueryState();
        long sum = 0;

        for (long n = 1; n < limit; n++) {
            long cube = n * n * n;
            sum += golombAt(cube, golomb, st);
        }

        return sum;
    }

    public static String solve() {
        long limit = 1000000;
        long maxQueryPosition = (limit - 1) * (limit - 1) * (limit - 1);
        int[] golomb = precomputeGolombUntil(maxQueryPosition);
        long ans = sumGolombCubes(limit, golomb);
        return String.valueOf(ans);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
