summaryrefslogtreecommitdiff
path: root/math/phi.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 01:24:14 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 01:24:14 +0100
commit98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch)
tree5113d5cc24d1ad5f93810b6442ce584a36950dc8 /math/phi.cpp
parentad3856a6b766087df0036de0b556f4700a6498c9 (diff)
parent8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff)
mzuenni tests
Diffstat (limited to 'math/phi.cpp')
-rw-r--r--math/phi.cpp21
1 files changed, 0 insertions, 21 deletions
diff --git a/math/phi.cpp b/math/phi.cpp
deleted file mode 100644
index 482a139..0000000
--- a/math/phi.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-ll phi(ll n) { // Laufzeit: O(sqrt(n))
- // Optimierung: Falls n prim, n - 1 zurückgeben
- ll result = n;
- for(ll i = 2; i * i <= n; ++i) {
- if(n % i == 0) { // Optimierung: Nur Primzahlen
- while(n % i == 0) n /= i;
- result -= result / i;
- }}
- if(n > 1) result -= result / n;
- return result;
-}
-
-// Sieb, falls alle Werte benötigt werden.
-// Laufzeit: O(N*log(log(N)))
-vector<ll> phi(n + 1);
-for (int i = 1; i <= n; i++) phi[i] = i;
-for (int i = 2; i <= n; i++) if (phi[i] == i) {
- for (int j = i; j <= n; j += i) {
- phi[j] /= i;
- phi[j] *= i - 1;
-}}