prime.cc
/* The above will be fooled by Carmichael numbers!  If we try a's coprime
   to N.  Try for 172081, a Carmichael number, with prime factorization
   7 * 13 * 31 * 61.  */
The above will be fooled by Carmichael numbers.  If we try a's coprime
to N.  Try for 172081, a Carmichael number, with prime factorization
7 * 13 * 31 * 61.
The above will be fooled by Carmichael numbers . If we try a ' s coprime to N . Try for 172081 a Carmichael number with prime factorization 7 * 13 * 31 * 61 .
static void
try_carm ()
{
  constexpr int n = 172081;
  for (auto i : { 9, 81, 123 })
    {
      if (coprime_p (n, i) && fermat_test (n, i))
	;
      else
	assert (!"huh?");
    }
}
static void try_carm ( ) { constexpr int n = 172081 ; for ( auto i : { 9 , 81 , 123 } ) { if ( coprime_p ( n , i ) && fermat_test ( n , i ) ) ; else assert ( ! " " ) ; } }
The above will be fooled by Carmichael numbers!
The above will be fooled by Carmichael numbers!
// NB: larger numbers would cause an overflow. /* Fooled as expected.  */