public static void main(String[] args) {
        Watch.start();
        int[] q = new int[N + 1];
        for (int i = 0; i <= N; i++)
            q[i] = i;
        boolean[] primes = new boolean[N + 1];
        Arrays.fill(primes, true);
        primes[0] = primes[1] = false;
        for (int i = 2; i <= N; i++)
            if (primes[i]) {
                q[i] = i - 1;
                for (int j = 2; i * j <= N; j++) {
                    primes[i * j] = false;
                    q[i * j] = (q[i * j] / i) * q[i];//phi(mn) = phi(n)phi(m) if m and n are co-prime
                }
            }
        long sum = 0;
        for (int i = 0; i < N; i++)
            if (primes[i]) {
                int chain = 1, number = i;
                while (number != 1) {
                    number = q[number];
                    chain++;
                    if (chain > 25) break;
                }
                if (chain == 25) sum += i;
            }
        System.out.println(sum);
        Watch.stop();
    }