aboutsummaryrefslogtreecommitdiff
path: root/challenge-175/laurent-rosenfeld/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-30 16:21:35 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-30 16:21:35 +0100
commit925d4a68cbfd366160835a465ea3dacc774c6203 (patch)
tree35449a9b65d9e1653d690c7a8d2de16831b3f915 /challenge-175/laurent-rosenfeld/python/ch-2.py
parent8d734718fe8e29e2c7b084c9efa08b1a7894aabe (diff)
downloadperlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.tar.gz
perlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.tar.bz2
perlweeklychallenge-club-925d4a68cbfd366160835a465ea3dacc774c6203.zip
- Added guest solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-175/laurent-rosenfeld/python/ch-2.py')
-rw-r--r--challenge-175/laurent-rosenfeld/python/ch-2.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/challenge-175/laurent-rosenfeld/python/ch-2.py b/challenge-175/laurent-rosenfeld/python/ch-2.py
new file mode 100644
index 0000000000..d465124687
--- /dev/null
+++ b/challenge-175/laurent-rosenfeld/python/ch-2.py
@@ -0,0 +1,13 @@
+import math
+
+cache = [0] * 10000
+
+def is_perfect_totient (n):
+ tot = 0
+ for i in range(1, n):
+ if (math.gcd(n, i) == 1):
+ tot += 1
+
+​ sum = tot + cache[tot] ​ cache[n] = sum ​ return n == sum
+​
+i = 1 ​ count = 0 ​ while count < 20: ​ if isperfecttotient(i): ​ print(i, end = ” “) ​ count += 1 ​ i += 1 ​ print(” “)