cin >> n; init_isp(n); for (int i = 1, x; i <= n; ++i) cin >> x, ++cnt[x]; for (int i = 1; i <= n; ++i) { int x = i, y = 1; while (x != 1) { int p = a[x], t = 0; while (x % p == 0) ++t, x /= p; for (int i = 1; i <= (t + 2) / 3; ++i) y *= p; } t[i] = y; } for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) c1[i] += cnt[j]; for (int i = 1; i <= n; ++i) c2[i] = c1[t[i]]; ll ans = 0; for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) ans += 1ll * phi[i] * mu[j / i] * c1[j] * c2[j]; cout << ans << "\n"; return0; }