Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean isPrime(int x) {
- if(x < 2)
- return false;
- for(int i = 2; i * i <= x; i++)
- if(x % i == 0)
- return false;
- return true;
- }
- public static int nextBiggerPow2(int x) {
- int p2 = 1;
- while(p2 <= x)
- p2 *= 2;
- return p2;
- }
- public static String isMersennePrime(int x) {
- if(x <= 0)
- return "Error!";
- if(isPrime(x) && nextBiggerPow2(x) - 1 == x)
- return "Yes";
- return "No";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement