Skip to content

Commit e2a8e9f

Browse files
committed
isComposite
1 parent 10ce0f5 commit e2a8e9f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Math/Factors.scope

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func bool isPrime(int n) {
1414

1515
// Starting at 2 and while i <= sqrt(n) (or i * i <= n)
1616
int i = 2;
17-
while (i * i < n + 1) {
17+
while (i * i <= n) {
1818
// If n is divisible by i, than it is not prime
1919
if (n % i == 0) {
2020
ret false;
@@ -27,6 +27,16 @@ func bool isPrime(int n) {
2727
ret true;
2828
}
2929

30+
/%
31+
@unoptimized: This functions is slow for large values.
32+
@complexity: O(sqrt(@"n"))
33+
34+
Returns whether or not @"n" is composite.
35+
%/
36+
func bool isComposite(int n) {
37+
ret !isPrime(n);
38+
}
39+
3040
/%
3141
Returns the greatest common divisor/factor (a.k.a. GCD, HCD, GCF, HCF) of @"a" and @"b".
3242
%/

0 commit comments

Comments
 (0)