Cunningham chain | Java program for cunningham chain Function to print the series of second kind ; Function to print Cunningham chain of the second kind ; Iterate till all elements are printed ; check prime or not ; Driver Code
class GFG { static void print ( int p0 ) { int p1 , i = 0 , x , flag , k ; while ( true ) { flag = 1 ; x = ( int ) ( Math . pow ( 2 , i ) ) ; p1 = x * p0 - ( x - 1 ) ; for ( k = 2 ; k < p1 ; k ++ ) { if ( p1 % k == 0 ) { flag = 0 ; break ; } } if ( flag == 0 ) break ; System . out . print ( p1 + " ▁ " ) ; i ++ ; } } public static void main ( String [ ] args ) { int p0 = 19 ; print ( p0 ) ; } }