Number Theory ------ Euler function

 

 

definition:  

  F (n) which is x in the interval [1, n-1} satisfying gcd (x, n) is equal to the number of x 1 (i.e., the number of x and n are relatively prime)

 

evaluate:

  First to n 'uniquely decomposed, removed all prime factors of   F. (N-) = n-* (1-1 of / P . 1 ) * (1-1 of / P 2 ) ...... * (1-1 of / P n- 

 

The only decomposition theorem :

   Any integer n can be written as    n = P . 1 E . 1     * P 2 E 2       ... * P N E    (where p is a prime number, e is the index )    

 

 

 


 

 

/*
nature:
        1. Assuming n is prime, then F (n) = n-1
        2. Assuming m, n prime, then F (n * m) = F (n) * (m) F (also a product of the nature of the function, is especially important)
        3. Let n is odd, F (2 * n) = F (n) proved to be very simple, and prime to n 2, and F (2) = 1, namely: F (2 * n) = F (n) * F (2) = F (n) 
        4. Only F (2) = 1, the value of the other F (n) is an even number
        5. A number of the sum of all prime factors: :( F (n) * n / 2) 
        6.a F. (N-) % n-. 1 = (n-%) (A, n-prime) -----> Euler's theorem
            The nature 6, when n is a prime number, it becomes the Fermat's little theorem A n. 1- %. 1 n = (n%)

*/ 

 

 

. 1 typedef Long  Long LL;
 2 LL Euler ( int n-) {
 . 3      LL ANS = . 1 ;
 . 4      for (LL I = 2 ; I * I <= n-; I ++ ) {
 . 5          IF (n-% I == 0 ) {     
 . 6              * = ANS (I- . 1 );    // because Euler function is multiplicative function 
. 7              n-/ = I;
 . 8              the while (n-I% == 0 ) {
 . 9                  n-/ = I;
 10                  ANS * = I;
 . 11              }
12          }
 13      }
 14      if (n> 1 ) years * = (n- 1 );
15      return year;
16 }
Code implementation part

 

 

Forum:

 

 

hdu1286 (template title)

 

 1 #include<iostream>
 2 using namespace std;
 3 typedef long long ll;
 4 int eulor(int n){
 5     int sum=1;
 6     for (int i=2;i*i<=n;i++){ 
 7         if (n%i==0){
 8             n/=i;
 9             sum*=(i-1);
10             while (n%i==0){
11                 n/=i;
12                 sum*=i;    
13             }
14         }
15     }
16     if (n>1)    sum*=(n-1);
17     return sum;
18 }
19 int main(){
20     int t;
21     cin>>t;
22     while(t--){
23         int n;
24         cin>>n;
25         cout<<eulor(n)<<endl;
26     }
27     return 0;
28 }

 

 

 

hdu2588

 

 1 #include<iostream>
 2 typedef long long ll;
 3 using namespace std;
 4 ll euler(int n){
 5     ll ans=1;
 6     for (ll i=2;i*i<=n;i++){
 7         if (n%i==0){     
 8             ans*=(i-1);   
 9             n/=i;
10             while (n%i==0){
11                 n/=i;
12                 ans*=i;
13             }
14         }
15     }
16     if (n>1)    ans*=(n-1);
17     return ans;
18 }
19 int main(){
20     int t;
21     cin>>t;
22     while (t--){
23         ll n,m,ans=0,i;
24         cin>>n>>m;
25         for (i=1;i*i<=n;i++){
26             if (n%i==0){
27                 if (i>=m)
28                     ans+=euler(n/i);
29                 if (n/i>=m) 
30                     ans+=euler(i);
31             }
32         }
33         if (i>m&&(i-1)*(i-1)==n)    ans-=euler(i-1);
34         cout<<ans<<endl;
35     }
36     
37     return 0;
38 }

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/q1204675546/p/11964519.html