Skip to content

Commit b553466

Browse files
committed
Math updates
1 parent c2489a2 commit b553466

File tree

4 files changed

+6
-90
lines changed

4 files changed

+6
-90
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ $ java -cp classes com.williamfiset.algorithms.search.BinarySearch
243243
- [Prime number sieve (sieve of Eratosthenes)](src/main/java/com/williamfiset/algorithms/math/SieveOfEratosthenes.java) **- O(nlog(log(n)))**
244244
- [Prime number sieve (sieve of Eratosthenes, compressed)](src/main/java/com/williamfiset/algorithms/math/CompressedPrimeSieve.java) **- O(nlog(log(n)))**
245245
- [Totient function (phi function, relatively prime number count)](src/main/java/com/williamfiset/algorithms/math/EulerTotientFunction.java) **- O(√n)**
246-
- [Totient function using sieve (phi function, relatively prime number count)](src/main/java/com/williamfiset/algorithms/math/EulerTotientFunctionWithSieve.java) **- O(nlog(log(n)))**
247246
- [Extended euclidean algorithm](src/main/java/com/williamfiset/algorithms/math/ExtendedEuclideanAlgorithm.java) **- ~O(log(a + b))**
248247
- [Greatest Common Divisor (GCD)](src/main/java/com/williamfiset/algorithms/math/Gcd.java) **- ~O(log(a + b))**
249248
- [Fast Fourier transform (quick polynomial multiplication)](src/main/java/com/williamfiset/algorithms/math/FastFourierTransform.java) **- O(nlog(n))**

src/main/java/com/williamfiset/algorithms/math/BUILD

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ java_binary(
2121
runtime_deps = [":math"],
2222
)
2323

24-
# bazel run //src/main/java/com/williamfiset/algorithms/math:EulerTotientFunctionWithSieve
25-
java_binary(
26-
name = "EulerTotientFunctionWithSieve",
27-
main_class = "com.williamfiset.algorithms.math.EulerTotientFunctionWithSieve",
28-
runtime_deps = [":math"],
29-
)
30-
3124
# bazel run //src/main/java/com/williamfiset/algorithms/math:FastFourierTransform
3225
java_binary(
3326
name = "FastFourierTransform",

src/main/java/com/williamfiset/algorithms/math/EulerTotientFunctionWithSieve.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/main/java/com/williamfiset/algorithms/math/PrimalityCheck.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,13 @@ public static boolean isPrimeWheel30(long n) {
5555
return true;
5656
if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0)
5757
return false;
58+
// Gaps between consecutive residues coprime to 30: 7,11,13,17,19,23,29,31 (i.e. +4,+2,+4,+2,+4,+6,+2,+6).
59+
int[] gaps = {4, 2, 4, 2, 4, 6, 2, 6};
5860
long limit = (long) Math.sqrt(n);
59-
int[] offsets = {1, 7, 11, 13, 17, 19, 23, 29};
60-
for (long base = 0; base <= limit; base += 30)
61-
for (int offset : offsets) {
62-
long d = base + offset;
63-
if (d < 7)
64-
continue;
65-
if (d > limit)
66-
break;
67-
if (n % d == 0)
68-
return false;
69-
}
61+
int gi = 0;
62+
for (long d = 7; d <= limit; d += gaps[gi++ % 8])
63+
if (n % d == 0)
64+
return false;
7065
return true;
7166
}
7267

0 commit comments

Comments
 (0)