Last active
February 10, 2024 13:21
-
-
Save Luna-Klatzer/b16e063e081e55d80081560825c2245d to your computer and use it in GitHub Desktop.
Simple Kipper program to get the prime factors of a number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def primeFactors(n: num) -> void { | |
while (n % 2 == 0) { | |
print("2"); | |
n /= 2; | |
} | |
// For all non-even divisors | |
for (var i: num = 3; i * i <= n; i += 2) { | |
while (n % i == 0) { | |
print(f"{i}"); | |
n /= i; | |
} | |
} | |
// In case the remainder is a prime number > 2 | |
if (n > 2) { | |
print(f"{n}"); | |
} | |
} | |
primeFactors(18); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:D