# include # include # include # include "fermat_factor.h" int main ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: fermat_factor_test() tests fermat_factor(). Licensing: This code is distributed under the MIT license. Modified: 09 April 2025 Author: John Burkardt */ { int f1; int f2; int i; int n; int n_test[4] = { 39, 25951, 2025090001, 2027651281 }; timestamp ( ); printf ( "\n" ); printf ( "fermat_factor_test():\n" ); printf ( " C version\n" ); printf ( " fermat_factor() factors an integer\n" ); printf ( " using the Fermat method.\n" ); for ( i = 0; i < 4; i++ ) { n = n_test[i]; fermat_factor ( n, &f1, &f2 ); printf ( "\n" ); printf ( " Seeking factors of n = %d\n", n ); printf ( " %d * %d = %d\n", f1, f2, f1 * f2 ); } /* Terminate. */ printf ( "\n" ); printf ( "fermat_factor_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }