import java.util.*;

public class Euler127 {
    public static void main(String[] args) {
        int limit = 120000;
        int[] rad = new int[limit];
        Arrays.fill(rad, 1);
        boolean[] isPrime = new boolean[limit];
        Arrays.fill(isPrime, true);
        isPrime[0] = isPrime[1] = false;
        for (int p = 2; p < limit; p++) {
            if (!isPrime[p])
                continue;
            for (int m = p; m < limit; m += p) {
                rad[m] *= p;
                if (m > p)
                    isPrime[m] = false;
            }
        }
        int[][] byRad = new int[limit - 1][2];
        for (int i = 0; i < limit - 1; i++) {
            byRad[i][0] = rad[i + 1];
            byRad[i][1] = i + 1;
        }
        Arrays.sort(byRad, (a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]);
        long total = 0;
        for (int c = 3; c < limit; c++) {
            int rc = rad[c];
            int th = c / rc;
            for (int[] ar : byRad) {
                if (ar[0] >= th)
                    break;
                int a = ar[1];
                if (a >= (c + 1) / 2)
                    continue;
                int b = c - a;
                if ((long) ar[0] * rad[b] * rc >= c)
                    continue;
                if (gcd(a, b) != 1)
                    continue;
                total += c;
            }
        }
        System.out.println(total);
    }

    static int gcd(int a, int b) {
        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }
        return a;
    }
}
