[Number theory] Euler function

Reference: Euler Euler function and linear sieve - Speech tree - CSDN blog

Euler (Eular) function $ \ varphi $

Euler function is a positive integer less than n and prime to n in number (the number of \ (\ varphi (. 1). 1 = \) )

(Coprime: number two and only common divisor $ 1 $)

$ $

$ $

Euler function \ (\ varphi \) character

1. If \ (n-\) is a prime number, \ (\ varphi (n-). 1-n-= \)

2. For \ (n-K = P ^ {} \) , there are \ (\ varphi (n) = (p-1) * p ^ {k-1} \)

3. Euler function is a multiplicative function, if \ (GCD (n-, m) =. 1 \) , i.e. \ (n-\) , \ (m \) coprime with \ (\ varphi (n * m ) = \ varphi (n) * \ varphi (m) \)

4. \(n = \sum_{i=1} ^{m} p_{i} ^{q_{i}}\) ,则\(\varphi (n) = n * \prod _{i=1} ^{m} (i - \frac{1}{p_{i}})\)

5. Euler's theorem: For coprime \ (A \) and \ (m \) , \ (A ^ {\ varphi (m)} \ equiv. 1 (MOD \) \ (m) \)

6. less than \ (n-\) and the \ (n-\) prime number and: \ (S = \ {n-FRAC * \ varphi (n-)} {2} \)

7. For the prime number \ (P \) , if the \ (n-\) \ (MOD \) \ (P = 0 \) , then \ (\ varphi (n-* P) = \ varphi (n-) * P \) ; If \ (n-\) \ (MOD \) \ (P \ NEQ 0 \) , then \ (\ varphi (n * p ) = \ varphi (n) * (p-1) \)

8. If \ (\ sum_ {D |} n-\ varphi (D) = n-\) , then \ (\ varphi (n) = \ sum_ {d | n} \ mu (d) * \ frac {n} { d} \)

Obviously we do not have access behind few written .... Anyway, first strategy


So with Euler mesh find the way primes (haze) value of Euler function code find

void getprime(int lim)
{
    nop[1]=1,phi[1]=0;
    for(int i=2;i<=lim;i++)
    {
        if(!nop[i])pri[++size]=i,phi[i]=i-1;
        for(int j=1;j<=size&&i*pri[j]<=lim;j++)
        {
            nop[i*pri[j]]=1;
            if(i%pri[j]==0)
            {
                phi[i*pri[j]]=phi[i]*pri[j];
                break;
            }
            else phi[i*pri[j]]=phi[i]*(pri[j]-1);
        }
    }
}

Talk about a few questions now

[HAOI2012] aliens

Questions surface:

Yi Liou found a number N quilt on her, she felt just find the smallest \ (X \) such that \ (\ varphi ^ {X} (N) =. 1 \)
. According to this $ x $ she had to find her kidnapped alien clue. Of course, she is not going to
count you please help her calculate the minimum \ (the X-\) .

Input:

The first line of a positive integer $ test $, followed \ (Test \) sets of data each set of data in the first line of a positive integer $ m $, followed
$ m $ rows each row two positive integers $ q_ {i} $ and \ (p_ {i} \)

Wherein \ (\ prod_ {i = 1 } ^ {m} p_ {i} ^ {q_ {i}} \) of \ (N \) standard exploded form.

1
2
2 2
3 1

Output:

\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ text {} \) per line integer \ (ANS \)

3

Sample explained:

\ (N = 12 is, \ varphi (12 is) =. 4, \ varphi (. 4) = 2, \ varphi (2) =. 1 \) , so the answer is 3.

\(\varphi(\prod_{i=1}^{m}p_{i}^{q_{i}})=\prod_{i=1}^{m}(p_{i}-1)p_{i}^{q_{i}-1}\)

\(\color{#ccc}\text{ }\)
\(\color{#ccc}\text{ }\)

\(\color{#ccc}\text{ }\)
\(\color{#ccc}\text{ }\)

analysis:

\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ {text} \)
\ (\ #ccc Color {} \ text {} \) is actually required is so entitled \ (\ varphi (\ varphi ... (\ varphi (N))) = 1 \) in \ (\ varphi \) the number of operation

By playing tableIt can be found only \ (\ varphi (1) \ ) and \ (\ varphi (2) \ ) is 1, it must take the last step before \ (N \) is converted to 2 (because you can not turn 1 ah, turn 1 on both), then according to the presented formula of the subject,

Guess you like

Origin www.cnblogs.com/lsy263/p/11266481.html