Euler functions
Euler functions, for positive integer n, the Euler function is the number of the number of n coprime less than or equal to N.
The general formula is:
F (x) = x * (1-1/p1) * (1-1/p2) * ... * (1-1/PN); P1,p2,p3.....pn is the qualitative factor of X. Each quality factor occurs only once. that is p1≠p2≠....pn; for example 12 = 2 * 2 * 3;2 can only be counted once.
With this Oraton-type, you can quickly solve the problem, the beginning I was done in a normal way, it is obvious that the time-out, a number of input at a time, it is easy to time out.
The following is the code for AC:
#include <iostream>using namespace std; #define MAX 33000int a[max];void make_eular () //Hit table {a[1] = 1;for (int i = 2 ; i < MAX; i++) {A[i] = i;} for (int j = 2; J < Max; J + +) //For each Euler function, {if (a[j] = = j) {for (int k = j; k < Max; k + + j)// from J to MAX, each number, a qualitative factor of K of J, calculated once. Plus the outer loop, the J layer, calculates the Euler function {//For each number . A[K] = a[k]/J * (J-1);}}} int main () {int n, t;make_eular (), CIN >> T;while (t--) {cin >> n;cout << a[n] << Endl;} return 0;}
Hangzhou Electric acm1286--to find new friend ~ Euler function application