Carmichael Number
\[ n \text{ is Carmichael number if} \\ b^{n-1} \equiv 1 \mod n \\ \text{for all } b, \quad \text{such that }\gcd(b, n) = 1, \quad 1 \lt b \lt n \]
Carmichael Number
public static boolean CarmichaelNumber(int n){
        for(int b=2; b<n; b++){
            if(gcd(b, n) == 1){
                BigDecimal bg = new BigDecimal(b);
                BigDecimal big = bg.pow(n-1);
                BigDecimal bgremainder = big.remainder(new BigDecimal(n));
                if(Integer.parseInt(bgremainder.toString()) != 1)
                    return false;
            }
        }
        return true;
    }