[Cpp]/* xmu 1447 Product Function Solution: when (a, B) = 1; then f (a * B) = f (a) * f (B ); x [I] indicates the sum [I] function of the Euler's function, indicating the number of factors p [I] indicates the I-th prime number */# include <iostream> # include <cstdio> # include <cmath> # include <algorithm> # define manx 1000001 using namespace std; int x [manx], sum [manx], p [manx]; bool s [manx]; void prime () {int num = 0; for (int I = 0; I <manx; I ++) s [I] = 0, x [I] = 0, sum [I] = 1, p [I] = 0; for (int I = 2; I * I <manx; I ++) {if (! S [I]) {p [num ++] = I; for (int j = 2; j * I <manx; j ++) s [I * j] = 1 ;}}for (int I = 2; I <manx; I ++) if (! S [I]) p [num ++] = I;} void oula () {for (int I = 2; I <manx; I ++) {if (! S [I]) {x [I] = I-1; sum [I] = 2; continue;} for (int j = 0; p [j] * p [j] <= I; j ++) {if (I % p [j] = 0) {if (I/p [j] % p [j]) {// only one p [j] Prime Factor sum [I] = sum [I/p [j] * 2; x [I] = x [I/p [j] * x [p [j];} else {// There may be multiple p [I] Prime Factor int ans = I; x [I] = x [I/p [j] * p [j]; while (ans % p [j] = 0) ans/= p [j]; /// understand this section. sum [I] = sum [ans] + sum [I/p [j] must combine mathematical knowledge. /// update the number of factors for I} break; // after processing the bounce loop }}} int main () {prime (); oula (); int t, n; scanf ("% d", & t); while (t --) {scanf ("% d", & n); printf ("% d \ n ", n-sum [n]-x [n] + 1 );}}