Here you can find the source of isMersenneNumber(BigInteger n)
Parameter | Description |
---|---|
n | a checking number |
public static boolean isMersenneNumber(BigInteger n)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { /**/*from ww w.j a v a2 s. c om*/ * Method to check if a given number is a Mersenne number (primality of the number is not checked). * Linear time.<br><br> * https://en.wikipedia.org/wiki/Mersenne_prime * @param n a checking number * @return true iff log<sub>2</sub>( n + 1 ) is a non-negative integer */ public static boolean isMersenneNumber(BigInteger n) { if (n.signum() < 0) return false; byte bytes[] = n.toByteArray(); byte b = bytes[0]; if ((b & (b + 1)) != 0) return false; for (int i = 1; i < bytes.length; i++) if (bytes[i] != -1) return false; return true; } }