main
Jan-Niclas Loosen 12 months ago
parent 9c30250122
commit f64a9186b5

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (UNI_Python)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10.6 WSL (Ubuntu): (/home/janniclas/.virtualenvs/Informationssysteme/bin/python)" project-jdk-type="Python SDK" />
</project>

@ -5,7 +5,7 @@
<excludeFolder url="file://$MODULE_DIR$/Virtualenv" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (UNI_Python)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10.6 WSL (Ubuntu): (/home/janniclas/.virtualenvs/Informationssysteme/bin/python)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,34 @@
# Jan-Niclas Loosen
# 1540907
def sieve_of_eratosthenes(limit):
primes = [True] * (limit + 1)
primes[0] = primes[1] = False # 0 and 1 are not primes
for num in range(2, int(limit ** 0.5) + 1): # only necessary to the square root of the limit
if primes[num]:
prime = num
for i in range(1,limit):
mult = prime * (i + 1)
if mult >= len(primes): # more loops are unnecessary
break
primes[mult] = False
return primes
def prime_factorization(n):
primes = sieve_of_eratosthenes(n)
factors = []
for i in range(2, n + 1):
if primes[i] and n % i == 0:
while n % i == 0:
factors.append(i)
n = n // i
return factors
# dialog for testing the functions
num = int(input("insert positive integer: "))
if num < 0 :
print("invalid input")
else:
print(prime_factorization(num))
Loading…
Cancel
Save