Find 2 ^ ( 2 ^ A ) % B | Java implementation of the above approach ; Function to return 2 ^ ( 2 ^ A ) % B ; Base case , 2 ^ ( 2 ^ 1 ) % B = 4 % B ; Driver code ; Print 2 ^ ( 2 ^ A ) % B
class GFG { static long F ( long A , long B ) { if ( A == 1 ) return ( 4 % B ) ; else { long temp = F ( A - 1 , B ) ; return ( temp * temp ) % B ; } } public static void main ( String args [ ] ) { long A = 25 , B = 50 ; System . out . println ( F ( A , B ) ) ; } }