From 7cf1a895761c9088eb7588f1f9db397226e5edd5 Mon Sep 17 00:00:00 2001 From: samsidx Date: Mon, 28 Jul 2014 12:49:45 +0530 Subject: [PATCH 1/2] Completed Euler's Totient Function Completed Euler's Totient Function --- src/basic/phi-function.txt | 78 +++++++++---- tools/.idea/.name | 1 + tools/.idea/encodings.xml | 5 + tools/.idea/misc.xml | 21 ++++ tools/.idea/modules.xml | 9 ++ tools/.idea/scopes/scope_settings.xml | 5 + tools/.idea/tools.iml | 9 ++ tools/.idea/vcs.xml | 7 ++ tools/.idea/workspace.xml | 159 ++++++++++++++++++++++++++ 9 files changed, 274 insertions(+), 20 deletions(-) create mode 100644 tools/.idea/.name create mode 100644 tools/.idea/encodings.xml create mode 100644 tools/.idea/misc.xml create mode 100644 tools/.idea/modules.xml create mode 100644 tools/.idea/scopes/scope_settings.xml create mode 100644 tools/.idea/tools.iml create mode 100644 tools/.idea/vcs.xml create mode 100644 tools/.idea/workspace.xml diff --git a/src/basic/phi-function.txt b/src/basic/phi-function.txt index 52ec02ef0..3dfc7420b 100644 --- a/src/basic/phi-function.txt +++ b/src/basic/phi-function.txt @@ -2,32 +2,70 @@ #Euler's Totient Function Also known as $\phi (n)$ i.e. **phi-function** it is just a count of coprimes (numbers, -having greatest common divisor of `1`) with `n` and not exceeding `n` itself. -Here `1` is regarded as a coprime to any number. +having greatest common divisor of `1`) with $n$ and not exceeding $n$ itself. +Here $1$ is regarded as a coprime to any number. -For example, `4` has two such coprimes - `1` and `2`. Any prime, `n` (like `7`) obviously have -`n-1` such coprimes. +$\phi (n) =$ the number of positive integers less than $n$ that are relatively prime to $n$ +where $n >=1$. + +For example, $4$ has two such coprimes - $1$ and $2$. Any prime, $n$ (like $7$) obviously have +$n - 1$ such coprimes. Here are values of $\phi(n)$ for first few positive integers: - N 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + N 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - Phi 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 + Phi(N) 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8 8 16 6 18 8 12 10 + +###Properties + +The following properties of Euler Totient Functin are enough to calculate if for any number. + +* If $p$ is a prime number, $\phi (p) = p - 1$ as $gcd(p, q) = 1$ where $1 <= q < p$. +* If $p$ is a prime number and $k > 0$, $\phi (p^k) = p^k - p^{(k - 1)}$ +* If $a$ and $b$ are relatively prime, $\phi (ab) = \phi (a) . \phi (b)$ + +We can get easily Euler function for any $n$ through factorization ( decomposing $n$ into its prime factors ). +If +>$n = {P_{1}}^{a_{1}} \cdot {P_{2}}^{a_{2}} \cdot {P_{3}}^{a_{3}} \cdot \ldots \cdot {P_{k}}^{a_{k}}$ +where $P_{i}$ are prime factors of $n$. + +>$\phi (n) = \phi ({P_{1}}^{a_{1}}) \cdot \phi ({P_{2}}^{a_{2}}) \cdot \ldots \cdot \phi ({P_{k}}^{a_{k}})$ +$= ({P_{1}}^{a_{1}} - {P_{1}}^{a_{1} - 1}) \cdot ({P_{2}}^{a_{2}} - {P_{2}}^{a_{2} - 1}) \cdot \ldots \cdot ({P_{k}}^{a_{k}} - {P_{k}}^{a_{k} - 1})$ +$= n \cdot (1 - \frac{1}{{P_{1}}^{a_{1}}}) \cdot (1 - \frac{1}{{P_{2}}^{a_{2}}}) \cdot \ldots \cdot (1 - \frac{1}{{P_{k}}^{a_{k}}})$ ###Algorithm -Here is the code for generating `phi(n)` in `Python 3`: - - def phi(n): - result = n - i = 2 - while i * i <= n: - if n % i == 0: - while n % i == 0: - n //= i - result -= result // i - i += 1 - if n > 1: - result -= result // n - return result +'C++' implementation: + + int phi(int n) { + int result = n; + for(int i = 2; i * i <= n; ++i) + if(n % i == 0) { + while(n % i == 0) + n /= i; + result -= result / i; + } + if(n > 1) + result -= result / n; + return result; + } + +###Applications of Euler's function + +The most famous and important property of Euler's function is expressed in **Euler's theorem** : +$a^{\phi (m)} = 1 (mod$ $m)$ $where$ $a$ and $m$ are relatively prime. + +In the particular case when, $m$ is a prime Euler's theorem turns into the so-called **Fermat's little theorem** : +$a^{(m - 1)} \equiv 1 \pmod m$ +Euler's theorem occurs quite often in practical applications + +###Practice Problems + +* [SPOJ #4141 [Euler Totient Function] [Difficulty: CakeWalk]](http://www.spoj.com/problems/ETF/) +* [UVA #10179 "Irreducible Basic Fractions" [Difficulty: Easy]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1120) +* [UVA #10299 "Relatives" [Difficulty: Easy]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1240) +* [UVA #11327 "Enumerating Rational Numbers" [Difficulty: Medium]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2302) +* [TIMUS #1673 "tolerance for the exam" [Difficulty: High]](http://acm.timus.ru/problem.aspx?space=1&num=1673) +**We will add more practice problems soon** \ No newline at end of file diff --git a/tools/.idea/.name b/tools/.idea/.name new file mode 100644 index 000000000..71e9f312d --- /dev/null +++ b/tools/.idea/.name @@ -0,0 +1 @@ +tools \ No newline at end of file diff --git a/tools/.idea/encodings.xml b/tools/.idea/encodings.xml new file mode 100644 index 000000000..e206d70d8 --- /dev/null +++ b/tools/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/tools/.idea/misc.xml b/tools/.idea/misc.xml new file mode 100644 index 000000000..4559dee05 --- /dev/null +++ b/tools/.idea/misc.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + CoffeeScript + + + + + + + + diff --git a/tools/.idea/modules.xml b/tools/.idea/modules.xml new file mode 100644 index 000000000..a5cc54049 --- /dev/null +++ b/tools/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tools/.idea/scopes/scope_settings.xml b/tools/.idea/scopes/scope_settings.xml new file mode 100644 index 000000000..922003b84 --- /dev/null +++ b/tools/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/tools/.idea/tools.iml b/tools/.idea/tools.iml new file mode 100644 index 000000000..6b8184f8e --- /dev/null +++ b/tools/.idea/tools.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tools/.idea/vcs.xml b/tools/.idea/vcs.xml new file mode 100644 index 000000000..def6a6a18 --- /dev/null +++ b/tools/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tools/.idea/workspace.xml b/tools/.idea/workspace.xml new file mode 100644 index 000000000..73e063cbd --- /dev/null +++ b/tools/.idea/workspace.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1406526471748 + 1406526471748 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9e971731c3bb4335d85cd56ad3bbd53694ec05cb Mon Sep 17 00:00:00 2001 From: samsidx Date: Tue, 29 Jul 2014 21:01:07 +0530 Subject: [PATCH 2/2] Removed .idea folder .idea folder has been removed. --- tools/.idea/.name | 1 - tools/.idea/encodings.xml | 5 - tools/.idea/misc.xml | 21 ---- tools/.idea/modules.xml | 9 -- tools/.idea/scopes/scope_settings.xml | 5 - tools/.idea/tools.iml | 9 -- tools/.idea/vcs.xml | 7 -- tools/.idea/workspace.xml | 159 -------------------------- 8 files changed, 216 deletions(-) delete mode 100644 tools/.idea/.name delete mode 100644 tools/.idea/encodings.xml delete mode 100644 tools/.idea/misc.xml delete mode 100644 tools/.idea/modules.xml delete mode 100644 tools/.idea/scopes/scope_settings.xml delete mode 100644 tools/.idea/tools.iml delete mode 100644 tools/.idea/vcs.xml delete mode 100644 tools/.idea/workspace.xml diff --git a/tools/.idea/.name b/tools/.idea/.name deleted file mode 100644 index 71e9f312d..000000000 --- a/tools/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -tools \ No newline at end of file diff --git a/tools/.idea/encodings.xml b/tools/.idea/encodings.xml deleted file mode 100644 index e206d70d8..000000000 --- a/tools/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/tools/.idea/misc.xml b/tools/.idea/misc.xml deleted file mode 100644 index 4559dee05..000000000 --- a/tools/.idea/misc.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - CoffeeScript - - - - - - - - diff --git a/tools/.idea/modules.xml b/tools/.idea/modules.xml deleted file mode 100644 index a5cc54049..000000000 --- a/tools/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tools/.idea/scopes/scope_settings.xml b/tools/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b84..000000000 --- a/tools/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/.idea/tools.iml b/tools/.idea/tools.iml deleted file mode 100644 index 6b8184f8e..000000000 --- a/tools/.idea/tools.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tools/.idea/vcs.xml b/tools/.idea/vcs.xml deleted file mode 100644 index def6a6a18..000000000 --- a/tools/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/tools/.idea/workspace.xml b/tools/.idea/workspace.xml deleted file mode 100644 index 73e063cbd..000000000 --- a/tools/.idea/workspace.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1406526471748 - 1406526471748 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy