import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Euler913 {

    static class PrimeData {
        int exp;
        long[] phi;
        long[] ord;
    }

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

    static class Pair {
        long p;
        int e;

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

    static List<Pair> factorize(long x, List<Integer> primes) {
        List<Pair> factors = new ArrayList<>();
        long n = x;
        for (int p : primes) {
            if ((long) p * p > n)
                break;
            if (n % p == 0) {
                int e = 0;
                while (n % p == 0) {
                    n /= p;
                    e++;
                }
                factors.add(new Pair(p, e));
            }
        }
        if (n > 1) {
            factors.add(new Pair(n, 1));
        }
        return factors;
    }

    static void addFactorization(Map<Long, Integer> acc, long n, List<Integer> primes) {
        if (n <= 1)
            return;
        List<Pair> factors = factorize(n, primes);
        for (Pair pair : factors) {
            acc.put(pair.p, acc.getOrDefault(pair.p, 0) + pair.e);
        }
    }

    static long orderPrimePower(long base, long p, int k, List<Integer> primes,
            Map<Long, Map<Long, Integer>> factorCache) {
        long mod = 1;
        for (int i = 0; i < k; i++)
            mod *= p;

        long phi = 1;
        for (int i = 0; i < k - 1; i++)
            phi *= p;
        phi *= (p - 1);

        if (!factorCache.containsKey(p - 1)) {
            Map<Long, Integer> f = new HashMap<>();
            for (Pair pair : factorize(p - 1, primes)) {
                f.put(pair.p, pair.e);
            }
            factorCache.put(p - 1, f);
        }

        Map<Long, Integer> fac = new HashMap<>(factorCache.get(p - 1));
        if (k > 1) {
            fac.put(p, fac.getOrDefault(p, 0) + k - 1);
        }

        long ordVal = phi;
        BigInteger B = BigInteger.valueOf(base);
        BigInteger M = BigInteger.valueOf(mod);

        for (Map.Entry<Long, Integer> entry : fac.entrySet()) {
            long q = entry.getKey();
            int e = entry.getValue();
            for (int i = 0; i < e; ++i) {
                if (ordVal % q != 0)
                    break;
                long cand = ordVal / q;
                if (B.modPow(BigInteger.valueOf(cand), M).equals(BigInteger.ONE)) {
                    ordVal = cand;
                } else {
                    break;
                }
            }
        }
        return ordVal;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static long lcm(long a, long b) {
        if (a == 0 || b == 0)
            return 0;
        return (a / gcd(a, b)) * b;
    }

    static long cyclesModSet = 0;

    static void dfs(int idx, long phiCur, long ordCur, List<PrimeData> data) {
        if (idx == data.size()) {
            cyclesModSet += phiCur / ordCur;
            return;
        }
        PrimeData pd = data.get(idx);
        for (int k = 0; k <= pd.exp; ++k) {
            long phiNext = phiCur * pd.phi[k];
            long ordNext = lcm(ordCur, pd.ord[k]);
            dfs(idx + 1, phiNext, ordNext, data);
        }
    }

    static long swapsFourthPowerDims(int n, int m, List<Integer> primes, Map<Long, Map<Long, Integer>> factorCache,
            Map<Long, Map<Long, Integer>> tFactorCache) {
        long uu = (long) n * m;
        long N = uu * uu * uu * uu;
        long g = (long) m * m * m * m;

        if (!tFactorCache.containsKey(uu)) {
            Map<Long, Integer> acc = new HashMap<>();
            addFactorization(acc, uu - 1, primes);
            addFactorization(acc, uu + 1, primes);
            addFactorization(acc, uu * uu + 1, primes);
            tFactorCache.put(uu, acc);
        }

        Map<Long, Integer> factors = tFactorCache.get(uu);
        List<PrimeData> data = new ArrayList<>();

        for (Map.Entry<Long, Integer> entry : factors.entrySet()) {
            long p = entry.getKey();
            int e = entry.getValue();

            PrimeData pd = new PrimeData();
            pd.exp = e;
            pd.phi = new long[e + 1];
            pd.ord = new long[e + 1];
            pd.phi[0] = 1;
            pd.ord[0] = 1;

            for (int k = 1; k <= e; ++k) {
                long po = 1;
                for (int i = 0; i < k - 1; i++)
                    po *= p;
                pd.phi[k] = po * (p - 1);
                pd.ord[k] = orderPrimePower(g, p, k, primes, factorCache);
            }
            data.add(pd);
        }

        cyclesModSet = 0;
        dfs(0, 1, 1, data);

        return N - 1 - cyclesModSet;
    }

    public static String solve() {
        List<Integer> primes = sievePrimes(100000);
        Map<Long, Map<Long, Integer>> factorCache = new HashMap<>();
        Map<Long, Map<Long, Integer>> tFactorCache = new HashMap<>();

        BigInteger ans = BigInteger.ZERO;
        for (int n = 2; n <= 100; ++n) {
            for (int m = n; m <= 100; ++m) {
                long res = swapsFourthPowerDims(n, m, primes, factorCache, tFactorCache);
                ans = ans.add(BigInteger.valueOf(res));
            }
        }
        return ans.toString();
    }

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