import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Euler489 {

    private static long mulMod(long a, long b, long mod) {
        BigInteger biA = BigInteger.valueOf(a);
        BigInteger biB = BigInteger.valueOf(b);
        BigInteger biMod = BigInteger.valueOf(mod);
        return biA.multiply(biB).mod(biMod).longValue();
    }

    private static long modPow(long base, long exp, long mod) {
        long result = 1 % mod;
        long cur = base % mod;
        while (exp > 0) {
            if ((exp & 1) != 0)
                result = mulMod(result, cur, mod);
            cur = mulMod(cur, cur, mod);
            exp >>= 1;
        }
        return result;
    }

    private static long modInvPrime(long a, long p) {
        return modPow(a, p - 2, p);
    }

    private static long[] egcd(long a, long b) {
        if (b == 0)
            return new long[] { a, 1, 0 };
        long[] res = egcd(b, a % b);
        long g = res[0];
        long x1 = res[1];
        long y1 = res[2];
        long x = y1;
        long y = x1 - y1 * (a / b);
        return new long[] { g, x, y };
    }

    private static long modInvCoprime(long a, long mod) {
        long x = egcd(a, mod)[1];
        long res = x % mod;
        if (res < 0)
            res += mod;
        return res;
    }

    private static long[] modSqrt(long n, long p) {
        if (p == 2)
            return new long[] { 1, n % p };
        n %= p;
        if (n == 0)
            return new long[] { 1, 0 };
        if (modPow(n, (p - 1) / 2, p) != 1)
            return new long[] { 0, 0 };
        if (p % 4 == 3)
            return new long[] { 1, modPow(n, (p + 1) / 4, p) };

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

        long z = 2;
        while (modPow(z, (p - 1) / 2, p) != p - 1)
            ++z;

        long c = modPow(z, q, p);
        long x = modPow(n, (q + 1) / 2, p);
        long t = modPow(n, q, p);
        int m = s;

        while (t != 1) {
            int i = 1;
            long t2 = mulMod(t, t, p);
            while (t2 != 1) {
                t2 = mulMod(t2, t2, p);
                ++i;
            }
            long b = modPow(c, 1L << (m - i - 1), p);
            x = mulMod(x, b, p);
            long b2 = mulMod(b, b, p);
            t = mulMod(t, b2, p);
            c = b2;
            m = i;
        }
        return new long[] { 1, x };
    }

    private static boolean isRootMod(long n, int a, int b, long mod) {
        BigInteger biN = BigInteger.valueOf(n);
        BigInteger biA = BigInteger.valueOf(a);
        BigInteger biB = BigInteger.valueOf(b);
        BigInteger biMod = BigInteger.valueOf(mod);

        BigInteger n3 = biN.multiply(biN).multiply(biN);
        BigInteger val1 = n3.add(biB).mod(biMod);
        if (!val1.equals(BigInteger.ZERO))
            return false;

        BigInteger na = biN.add(biA);
        BigInteger na3 = na.multiply(na).multiply(na);
        BigInteger val2 = na3.add(biB).mod(biMod);
        return val2.equals(BigInteger.ZERO);
    }

    private static List<Integer> sievePrimes(int limit) {
        boolean[] isPrime = new boolean[limit + 1];
        for (int i = 2; i <= limit; i++)
            isPrime[i] = true;
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= limit; ++i) {
            if (!isPrime[i])
                continue;
            primes.add(i);
            if ((long) i * i > limit)
                continue;
            for (int j = i * i; j <= limit; j += i) {
                isPrime[j] = false;
            }
        }
        return primes;
    }

    static class Factor {
        long p;
        int e;

        Factor(long p, int e) {
            this.p = p;
            this.e = e;
        }
    }

    private static List<Factor> factorize(long n, List<Integer> primes) {
        List<Factor> out = new ArrayList<>();
        long tmp = n;
        for (int p : primes) {
            if ((long) p * p > tmp)
                break;
            if (tmp % p != 0)
                continue;
            int e = 0;
            while (tmp % p == 0) {
                tmp /= p;
                ++e;
            }
            out.add(new Factor(p, e));
        }
        if (tmp > 1)
            out.add(new Factor(tmp, 1));
        return out;
    }

    private static void addFactor(List<Factor> factors, long p, int e) {
        for (Factor f : factors) {
            if (f.p == p) {
                f.e += e;
                return;
            }
        }
        factors.add(new Factor(p, e));
    }

    private static List<Long> solutionsModP(long p, int a, int b) {
        List<Long> sols = new ArrayList<>();
        if (p <= 5 || (a % p) == 0) {
            for (long n = 0; n < p; ++n) {
                if (isRootMod(n, a, b, p))
                    sols.add(n);
            }
            return sols;
        }

        if (p == 3)
            return sols;

        long inv3 = modInvPrime(3, p);
        long inv2 = modInvPrime(2, p);
        long aMod = a % p;
        long D = (p + p - mulMod(aMod, aMod, p)) % p;
        D = mulMod(D, inv3, p);

        long[] sqrtRes = modSqrt(D, p);
        if (sqrtRes[0] == 0)
            return sols;

        long sqrtD = sqrtRes[1];
        long[] roots = { sqrtD, (p - sqrtD) % p };
        for (long s : roots) {
            long tmp = (p + s - aMod) % p;
            long n = mulMod(tmp, inv2, p);
            if (isRootMod(n, a, b, p)) {
                if (!sols.contains(n))
                    sols.add(n);
            }
        }
        return sols;
    }

    static class PrimeSolutions {
        long mod = 1;
        List<Long> residues = new ArrayList<>();
    }

    private static PrimeSolutions solvePrimePower(long p, int maxExp, int a, int b) {
        PrimeSolutions res = new PrimeSolutions();
        res.residues.add(0L);

        List<Long> sols = solutionsModP(p, a, b);
        if (sols.isEmpty())
            return res;

        long mod = p;
        for (int exp = 1; exp < maxExp; ++exp) {
            long nextMod = mod * p;
            List<Long> next = new ArrayList<>();
            for (long r : sols) {
                for (long t = 0; t < p; ++t) {
                    long n = r + t * mod;
                    if (isRootMod(n, a, b, nextMod)) {
                        next.add(n);
                    }
                }
            }
            if (next.isEmpty())
                break;
            sols = next;
            mod = nextMod;
        }

        res.mod = mod;
        res.residues = sols;
        return res;
    }

    private static long crt(long a, long modA, long b, long modB) {
        long inv = modInvCoprime(modA % modB, modB);
        long t = (b + modB - (a % modB)) % modB;
        long k = mulMod(t, inv, modB);
        BigInteger biA = BigInteger.valueOf(a);
        BigInteger biModA = BigInteger.valueOf(modA);
        BigInteger biK = BigInteger.valueOf(k);
        return biA.add(biModA.multiply(biK)).longValue();
    }

    static class Precompute {
        List<Integer> primes;
        long[] aPow6;
        long[] bTerm;
        List<Factor>[] aFactors;
    }

    private static Precompute buildPrecompute(int maxA, int maxB) {
        Precompute pre = new Precompute();
        pre.primes = sievePrimes(200000);
        pre.aPow6 = new long[maxA + 1];
        pre.aFactors = new ArrayList[maxA + 1];
        pre.bTerm = new long[maxB + 1];

        for (int a = 1; a <= maxA; ++a) {
            BigInteger v = BigInteger.ONE;
            for (int i = 0; i < 6; ++i)
                v = v.multiply(BigInteger.valueOf(a));
            pre.aPow6[a] = v.longValue();
            pre.aFactors[a] = factorize(a, pre.primes);
        }

        for (int b = 1; b <= maxB; ++b) {
            pre.bTerm[b] = 27L * b * b;
        }

        return pre;
    }

    private static long computeG(int a, int b, Precompute pre) {
        long R = pre.aPow6[a] + pre.bTerm[b];
        List<Factor> factors = factorize(R, pre.primes);
        for (Factor f : pre.aFactors[a]) {
            addFactor(factors, f.p, 3 * f.e);
        }

        List<PrimeSolutions> blocks = new ArrayList<>();
        for (Factor f : factors) {
            PrimeSolutions sol = solvePrimePower(f.p, f.e, a, b);
            if (sol.mod > 1)
                blocks.add(sol);
        }
        if (blocks.isEmpty())
            return 0;

        blocks.sort((x, y) -> Integer.compare(x.residues.size(), y.residues.size()));

        long mod = 1;
        List<Long> residues = new ArrayList<>();
        residues.add(0L);

        for (PrimeSolutions block : blocks) {
            List<Long> next = new ArrayList<>();
            for (long r : residues) {
                for (long s : block.residues) {
                    next.add(crt(r, mod, s, block.mod));
                }
            }
            mod *= block.mod;
            residues = next;
        }

        return Collections.min(residues);
    }

    private static long computeH(int maxA, int maxB, Precompute pre) throws Exception {
        int total = maxA * maxB;
        int threads = Runtime.getRuntime().availableProcessors();
        if (threads <= 0)
            threads = 4;

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Future<Long>> futures = new ArrayList<>();

        int chunk = (total + threads - 1) / threads;
        for (int t = 0; t < threads; t++) {
            final int start = t * chunk;
            final int end = Math.min(total, start + chunk);
            futures.add(executor.submit(() -> {
                long sum = 0;
                for (int i = start; i < end; i++) {
                    int a = i / maxB + 1;
                    int b = i % maxB + 1;
                    sum += computeG(a, b, pre);
                }
                return sum;
            }));
        }

        long totalSum = 0;
        for (Future<Long> f : futures) {
            totalSum += f.get();
        }
        executor.shutdown();
        return totalSum;
    }

    public static void main(String[] args) throws Exception {
        int maxA = 18;
        int maxB = 1900;
        Precompute pre = buildPrecompute(maxA, maxB);
        long result = computeH(maxA, maxB, pre);
        System.out.println(result);
    }
}
