public class Euler676 {

    static final long MOD16 = 10000000000000000L;

    static long addMod(long a, long b) {
        long s = a + b;
        if (s >= MOD16 || s < a) {
            return s - MOD16;
        }
        return s;
    }

    static long mulMod(long a, long b) {
        long res = 0;
        a %= MOD16;
        b %= MOD16;
        while (b > 0) {
            if ((b & 1) != 0) {
                res += a;
                if (res >= MOD16)
                    res -= MOD16;
            }
            a += a;
            if (a >= MOD16)
                a -= MOD16;
            b >>= 1;
        }
        return res;
    }

    static int maxBit(long n) {
        if (n == 0)
            return 0;
        return 64 - Long.numberOfLeadingZeros(n);
    }

    static long M(long n, int k, int l) {
        if (n == 0) {
            return 0;
        }

        int max_bit = maxBit(n);

        int[] coeff = new int[max_bit];
        int max_abs = 0;
        for (int p = 0; p < max_bit; ++p) {
            coeff[p] = (1 << (p % k)) - (1 << (p % l));
            max_abs += Math.abs(coeff[p]);
        }

        int offset = max_abs;
        int width = 2 * max_abs + 1;

        long[] cntLo = new long[width];
        long[] cntHi = new long[width];
        long[] sumLo = new long[width];
        long[] sumHi = new long[width];

        cntHi[offset] = 1L;

        for (int pos = max_bit - 1; pos >= 0; --pos) {
            long[] ncntLo = new long[width];
            long[] ncntHi = new long[width];
            long[] nsumLo = new long[width];
            long[] nsumHi = new long[width];

            int lim = (int) ((n >> pos) & 1L);
            int c = coeff[pos];
            long bitValue = (1L << pos) % MOD16;

            for (int idx = 0; idx < width; ++idx) {
                long c0 = cntLo[idx];
                if (c0 != 0L) {
                    long s0 = sumLo[idx];

                    ncntLo[idx] = addMod(ncntLo[idx], c0);
                    nsumLo[idx] = addMod(nsumLo[idx], s0);

                    int j = idx + c;
                    ncntLo[j] = addMod(ncntLo[j], c0);
                    long add1 = addMod(s0, mulMod(c0, bitValue));
                    nsumLo[j] = addMod(nsumLo[j], add1);
                }

                long c1 = cntHi[idx];
                if (c1 == 0L) {
                    continue;
                }
                long s1 = sumHi[idx];

                if (lim == 0) {
                    ncntHi[idx] = addMod(ncntHi[idx], c1);
                    nsumHi[idx] = addMod(nsumHi[idx], s1);
                } else {
                    ncntLo[idx] = addMod(ncntLo[idx], c1);
                    nsumLo[idx] = addMod(nsumLo[idx], s1);

                    int j = idx + c;
                    ncntHi[j] = addMod(ncntHi[j], c1);
                    long add1 = addMod(s1, mulMod(c1, bitValue));
                    nsumHi[j] = addMod(nsumHi[j], add1);
                }
            }

            cntLo = ncntLo;
            cntHi = ncntHi;
            sumLo = nsumLo;
            sumHi = nsumHi;
        }

        return addMod(sumLo[offset], sumHi[offset]);
    }

    public static String solve() {
        long ans = 0L;
        for (int k = 3; k <= 6; ++k) {
            for (int l = 1; l <= k - 2; ++l) {
                ans = addMod(ans, M(10000000000000000L, k, l));
            }
        }
        return String.format("%016d", ans);
    }

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