# Include <cstdio> # include <cstring> using namespace STD; # define CLR (a, B) memset (a, B, sizeof ()) # define maxn 1010int Phi [maxn], farey [maxn], n, T; void get_euler () // name the Euler function table {CLR (PHI, 0 ); phi [1] = 1; for (INT I = 2; I <maxn; ++ I) {If (! Phi [I]) {for (Int J = I; j <maxn; j + = I) {If (! Phi [J]) Phi [J] = J; Phi [J] = Phi [J]/I * (I-1) ;}}} void CAL () {farey [1] = 1 + Phi [1]; // based on the relationship between the farey series and the Euler function, initialize the farey Series F [1] to 2 for (INT I = 2; I <= maxn; ++ I) farey [I] = Phi [I] + farey [I-1];} int main () {get_euler (); CAL (); scanf ("% d", & T); For (INT I = 1; I <= T; ++ I) {scanf ("% d", & N ); printf ("% d \ n", I, n, farey [N] * 2-1);} return 0 ;}Code Jun
Poj 3090 visible lattice points (French record series + Euler's function)