import java.util.ArrayList;
import java.util.Collections;

public class Euler821 {

    static long countCoprime6(long x) {
        if (x <= 0)
            return 0;
        return x - x / 2 - x / 3 + x / 6;
    }

    static ArrayList<Long> generateSmooth(long N) {
        ArrayList<Long> v = new ArrayList<>();
        for (long p2 = 1; p2 <= N;) {
            for (long cur = p2; cur <= N;) {
                v.add(cur);
                if (cur > N / 3)
                    break;
                cur *= 3;
            }
            if (p2 > N / 2)
                break;
            p2 *= 2;
        }
        Collections.sort(v);
        ArrayList<Long> res = new ArrayList<>();
        for (long x : v) {
            if (res.isEmpty() || res.get(res.size() - 1) != x) {
                res.add(x);
            }
        }
        return res;
    }

    static ArrayList<Long> generateBad(long N) {
        ArrayList<Long> b = new ArrayList<>();
        if (6 <= N)
            b.add(6L);
        if (24 <= N)
            b.add(24L);
        if (54 <= N)
            b.add(54L);

        long x = 384;
        while (x <= N) {
            b.add(x);
            if (x > N / 8)
                break;
            x *= 8;
        }

        x = 243;
        while (x <= N) {
            b.add(x);
            if (x > N / 27)
                break;
            x *= 27;
        }

        Collections.sort(b);
        ArrayList<Long> res = new ArrayList<>();
        for (long val : b) {
            if (res.isEmpty() || res.get(res.size() - 1) != val) {
                res.add(val);
            }
        }
        return res;
    }

    public static String solve() {
        long N = 10000000000000000L;
        ArrayList<Long> smooth = generateSmooth(N);
        ArrayList<Long> bad = generateBad(N);

        long[] fAt = new long[smooth.size()];
        int ib = 0;
        long f = 0;
        for (int i = 0; i < smooth.size(); i++) {
            if (ib < bad.size() && smooth.get(i).equals(bad.get(ib))) {
                ib++;
            } else {
                f++;
            }
            fAt[i] = f;
        }

        // use BigInteger or java.math if it overflows, but maximum is sum of fAt * cnt
        // The max of fAt is smooth.size() which is around ~1200
        // max of cnt is N/L. So max sum happens at large N/L * fAt.
        // N = 10^16. Max product is roughly 1200 * 10^16 = 1.2 * 10^19.
        // Needs java.math.BigInteger, wait. The answer in C++ used `__int128_t`!
        // So we must use BigInteger for the `ans`.
        java.math.BigInteger ans = java.math.BigInteger.ZERO;

        int n = smooth.size();
        for (int i = 0; i < n; i++) {
            long L = smooth.get(i);
            long R = (i + 1 < n) ? smooth.get(i + 1) - 1 : N;
            if (R > N)
                R = N;

            long mLow = N / (R + 1) + 1;
            long mHigh = N / L;
            if (mLow > mHigh)
                continue;

            long cnt = countCoprime6(mHigh) - countCoprime6(mLow - 1);

            java.math.BigInteger term = java.math.BigInteger.valueOf(fAt[i])
                    .multiply(java.math.BigInteger.valueOf(cnt));
            ans = ans.add(term);
        }

        return ans.toString();
    }

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