We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9629aef + c785fc9 commit 48c7164Copy full SHA for 48c7164
Decomposing_factors.py
@@ -0,0 +1,17 @@
1
+def prime_factors(n):
2
+ final = []
3
+ rstr = ''
4
+ while n != 1:
5
+ for x in range(2,n+1):
6
+ if n % x == 0:
7
+ n //= x
8
+ final.append(x)
9
+ break
10
+ for x in final:
11
+ if f'({x}**{final.count(x)})' in rstr:
12
+ continue
13
+ rstr += f'({x}**{final.count(x)})' if final.count(x) > 1 else f'({x})'
14
+ return rstr
15
+
16
+#Function that decomposes number into their base multiplicants. Usefull for simplifications of square roots etc.
17
+#Example: prime_factors(30) outputs (2)(3)(5) because 30 = 2 * 3 * 5
0 commit comments