Here you can find the source of isFermatPrime(BigInteger f)
Parameter | Description |
---|---|
f | a checking number |
public static boolean isFermatPrime(BigInteger f)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { /**//from w w w . j a v a 2s . com * Fermat number deterministic primality test * (Fermat number is an integer in the form F<sub>n</sub> = 2<sup>2^n</sup> + 1). * Constant time. * @param f a checking number * @return true iff f is a Fermat number and f is prime */ public static boolean isFermatPrime(BigInteger f) { if (f.signum() <= 0) return false; if (f.bitLength() <= 31) { // The only prime Fermat numbers in BigInteger range // are the first five: 3, 5, 17, 257, 65537. switch (f.intValue()) { case 3: case 5: case 17: case 257: case 65537: return true; default: return false; } } return false; } }