Implementation of Wilson Primality test | Java implementation to check if a number is prime or not using Wilson Primality Test ; Function to calculate the factorial ; Function to check if the number is prime or not ; Driver code
public class Main { public static long fact ( int p ) { if ( p <= 1 ) return 1 ; return p * fact ( p - 1 ) ; } public static long isPrime ( int p ) { if ( p == 4 ) return 0 ; return ( fact ( p >> 1 ) % p ) ; } public static void main ( String [ ] args ) { if ( isPrime ( 127 ) == 0 ) { System . out . println ( 0 ) ; } else { System . out . println ( 1 ) ; } } }