Check if number is prime and of the form ( 2 ^ q + 1 ) / 3
if ( isPrime ( n ) && ( isPowerOfTwo ( n * 3 - 1 ) ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }