# include # include # include using namespace std; # include "prime_fermat.hpp" int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // prime_fermat_test() tests prime_fermat(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 20 September 2024 // // Author: // // John Burkardt // { int i; int k; int n; int n_test[] = { 11, 15, 221 }; bool value; timestamp ( ); cout << "\n"; cout << "prime_fermat_test():\n"; cout << " C++ version\n"; cout << " prime_fermat() applies Fermat's primality test to an integer.\n"; k = 3; cout << "\n"; cout << " The test will be repeated with " << k << " different bases.\n"; cout << "\n"; for ( i = 0; i < 3; i++ ) { n = n_test[i]; value = is_prime ( n, k ); if ( value ) { cout << " " << n << " may be a prime.\n"; } else { cout << " " << n << " is definitely not a prime.\n"; } } // // Terminate. // cout << "\n"; cout << "prime_fermat_test():\n"; cout << " Normal end of execution.\n"; timestamp ( ); return 0; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }