Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import java.math.BigInteger;
|
||||
|
||||
public class PrimaltyByWilsonsTheorem {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.printf("Primes less than 100 testing by Wilson's Theorem%n");
|
||||
for ( int i = 0 ; i <= 100 ; i++ ) {
|
||||
if ( isPrime(i) ) {
|
||||
System.out.printf("%d ", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean isPrime(long p) {
|
||||
if ( p <= 1) {
|
||||
return false;
|
||||
}
|
||||
return fact(p-1).add(BigInteger.ONE).mod(BigInteger.valueOf(p)).compareTo(BigInteger.ZERO) == 0;
|
||||
}
|
||||
|
||||
private static BigInteger fact(long n) {
|
||||
BigInteger fact = BigInteger.ONE;
|
||||
for ( int i = 2 ; i <= n ; i++ ) {
|
||||
fact = fact.multiply(BigInteger.valueOf(i));
|
||||
}
|
||||
return fact;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue