feat: add prime
This commit is contained in:
18
src/main/java/me/hatter/math/Prime.java
Normal file
18
src/main/java/me/hatter/math/Prime.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user