feat: add prime

This commit is contained in:
2025-07-19 20:51:29 +08:00
parent fb77e54324
commit 94f77fdd26

View File

@@ -0,0 +1,18 @@
package me.hatter.math;
public class Prime {
// 试除法
// https://oi-wiki.org/math/number-theory/prime/
public static boolean isPrimeTryingDivision(long a) {
if (a < 2) {
return false;
}
for (long i = 2; i < a; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
}