import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.*;

public class Euler699 {
    static long gcd(long a, long b) {
        while (b != 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }

    static long mulMod(long a, long b, long mod) {
        return BigInteger.valueOf(a).multiply(BigInteger.valueOf(b)).mod(BigInteger.valueOf(mod)).longValue();
    }

    static long powMod(long a, long d, long mod) {
        long r = 1;
        while (d > 0) {
            if ((d & 1) != 0)
                r = mulMod(r, a, mod);
            a = mulMod(a, a, mod);
            d >>= 1;
        }
        return r;
    }

    static boolean isPrime(long n) {
        if (n < 2)
            return false;
        long[] smallPrimes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
        for (long p : smallPrimes) {
            if (n == p)
                return true;
            if (n % p == 0)
                return false;
        }

        long d = n - 1;
        int s = 0;
        while ((d & 1) == 0) {
            d >>= 1;
            s++;
        }

        long[] bases = { 2L, 325L, 9375L, 28178L, 450775L, 9780504L, 1795265022L };
        for (long a : bases) {
            if (a % n == 0)
                continue;
            long x = powMod(a, d, n);
            if (x == 1 || x == n - 1)
                continue;
            boolean composite = true;
            for (int i = 1; i < s; i++) {
                x = mulMod(x, x, n);
                if (x == n - 1) {
                    composite = false;
                    break;
                }
            }
            if (composite)
                return false;
        }
        return true;
    }

    static long pollardRho(long n) {
        if ((n & 1) == 0)
            return 2;
        if (n % 3 == 0)
            return 3;

        ThreadLocalRandom rand = ThreadLocalRandom.current();
        while (true) {
            long c = rand.nextLong(1, n);
            long x = rand.nextLong(0, n);
            long y = x;
            long d = 1;

            while (d == 1) {
                x = (mulMod(x, x, n) + c) % n;
                long ty = (mulMod(y, y, n) + c) % n;
                y = (mulMod(ty, ty, n) + c) % n;

                long diff = Math.abs(x - y);
                d = gcd(diff, n);
            }
            if (d != n)
                return d;
        }
    }

    static void factor(long n, List<Long> fac) {
        if (n == 1)
            return;
        if (isPrime(n)) {
            fac.add(n);
            return;
        }
        long d = pollardRho(n);
        factor(d, fac);
        factor(n / d, fac);
    }

    static class FactorCache {
        Map<Long, List<Long>> mp = new HashMap<>();

        List<Long> get(long n) {
            if (mp.containsKey(n))
                return mp.get(n);
            List<Long> f = new ArrayList<>();
            if (n > 1) {
                List<Long> tmp = new ArrayList<>();
                factor(n, tmp);
                Collections.sort(tmp);
                for (long p : tmp) {
                    if (f.isEmpty() || f.get(f.size() - 1) != p) {
                        f.add(p);
                    }
                }
            }
            mp.put(n, f);
            return f;
        }
    }

    static int v3(long x) {
        int c = 0;
        while (x % 3 == 0) {
            x /= 3;
            c++;
        }
        return c;
    }

    static long sigmaPrimePower(long p, int e, long pPow) {
        BigInteger nextPow = BigInteger.valueOf(pPow).multiply(BigInteger.valueOf(p));
        return nextPow.subtract(BigInteger.ONE).divide(BigInteger.valueOf(p - 1)).longValue();
    }

    static class SolverA {
        long A;
        long limit;
        int maxv3;
        long sumM = 0;
        HashSet<Long> visitedM = new HashSet<>();
        FactorCache cache = new FactorCache();
        List<Long> used = new ArrayList<>();

        SolverA(long a, long limit, int maxv3) {
            this.A = a;
            this.limit = limit;
            this.maxv3 = maxv3;
        }

        void dfs(long m, long num, long den, int v3sig, long sigmaM) {
            if (m > limit)
                return;
            if (!visitedM.add(m))
                return;

            if (den == 1 && v3sig <= maxv3) {
                sumM += m;
            }

            List<Long> cand = new ArrayList<>(cache.get(num));
            cand.add(2L);
            Collections.sort(cand);
            List<Long> uniqCand = new ArrayList<>();
            for (long p : cand) {
                if (uniqCand.isEmpty() || uniqCand.get(uniqCand.size() - 1) != p) {
                    uniqCand.add(p);
                }
            }

            for (long p : uniqCand) {
                if (p == 3)
                    continue;
                if (used.contains(p))
                    continue;

                long pPow = p;
                for (int e = 1;; e++) {
                    if (BigInteger.valueOf(m).multiply(BigInteger.valueOf(pPow))
                            .compareTo(BigInteger.valueOf(limit)) > 0)
                        break;

                    long sig = sigmaPrimePower(p, e, pPow);
                    int v3f = v3(sig);

                    if (v3sig + v3f <= maxv3) {
                        long denomFactor = pPow;
                        long sigFactor = sig;

                        long num1 = num;
                        long den1 = den;

                        long g1 = gcd(num1, denomFactor);
                        num1 /= g1;
                        denomFactor /= g1;

                        long g2 = gcd(sigFactor, den1);
                        sigFactor /= g2;
                        den1 /= g2;

                        long newNum = num1 * sigFactor;
                        long newDen = den1 * denomFactor;

                        long newM = m * pPow;
                        long newSigmaM = sigmaM * sig;

                        used.add(p);
                        dfs(newM, newNum, newDen, v3sig + v3f, newSigmaM);
                        used.remove(used.size() - 1);
                    }

                    if (pPow > limit / p)
                        break;
                    pPow *= p;
                }
            }
        }
    }

    public static String solve() {
        long N = 100000000000000L;
        List<long[]> tasks = new ArrayList<>();
        long pow3 = 1;
        int a = 1;
        while (true) {
            pow3 *= 3;
            if (pow3 > N)
                break;
            tasks.add(new long[] { a, pow3 });
            a++;
        }

        int threads = Runtime.getRuntime().availableProcessors();
        if (threads < 1)
            threads = 1;
        ExecutorService pool = Executors.newFixedThreadPool(threads);
        List<Future<Long>> futures = new ArrayList<>();

        for (long[] task : tasks) {
            futures.add(pool.submit(() -> {
                int t_a = (int) task[0];
                long t_p3 = task[1];
                long limit = N / t_p3;
                long t_val = t_p3 * 3 - 1;
                long A = t_val / 2;
                SolverA solver = new SolverA(A, limit, t_a - 1);
                solver.dfs(1L, A, 1L, 0, 1L);
                return t_p3 * solver.sumM;
            }));
        }

        long total = 0;
        for (Future<Long> f : futures) {
            try {
                total += f.get();
            } catch (Exception e) {
            }
        }
        pool.shutdown();
        return Long.toString(total);
    }

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