# include # include # include # include using namespace std; # include "fermat_factor.hpp" int main ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // fermat_factor_test() tests fermat_factor(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 10 April 2025 // // Author: // // John Burkardt // { int f1; int f2; int i; int n; int n_test[4] = { 39, 25951, 2025090001, 2027651281 }; timestamp ( ); cout << "\n"; cout << "fermat_factor_test():\n"; cout << " C++ version\n"; cout << " fermat_factor() factors an integer\n"; cout << " using the Fermat method.\n"; for ( i = 0; i < 4; i++ ) { n = n_test[i]; fermat_factor ( n, f1, f2 ); cout << "\n"; cout << " Seeking factors of n = " << n << "\n"; cout << " " << f1 << " * " << f2 << " = " << f1 * f2 << "\n"; } // // Terminate. // cout << "\n"; cout << "fermat_factor_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 }