Vantieghems Theorem for Primality Test | Java code to verify Vantieghem 's Theorem ; Check if above condition is satisfied ; product of previous powers of 2 ; Driver code
import java . util . * ; class GFG { static void checkVantieghemsTheorem ( int limit ) { long prod = 1 ; for ( long n = 2 ; n < limit ; n ++ ) { if ( ( ( prod - n < 0 ? 0 : prod - n ) % ( ( 1 << n ) - 1 ) ) == 0 ) System . out . print ( n + " is primeNEW_LINE"); prod *= ( ( 1 << n ) - 1 ) ; } } public static void main ( String [ ] args ) { checkVantieghemsTheorem ( 10 ) ; } }