Advertisement
marius7122

Untitled

Apr 5th, 2022
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. public static boolean isPrime(int x) {
  2.         if(x < 2)
  3.             return false;
  4.         for(int i = 2; i * i <= x; i++)
  5.             if(x % i == 0)
  6.                 return false;
  7.         return true;
  8.     }
  9.  
  10.     public static int nextBiggerPow2(int x) {
  11.         int p2 = 1;
  12.         while(p2 <= x)
  13.             p2 *= 2;
  14.         return p2;
  15.     }
  16.  
  17.     public static String isMersennePrime(int x) {
  18.         if(x <= 0)
  19.             return "Error!";
  20.  
  21.         if(isPrime(x) && nextBiggerPow2(x) - 1 == x)
  22.             return "Yes";
  23.         return "No";
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement