//$Header$ //******************************************************************************** //Copyright (c) 2003, 2018 David T. Ashley. //******************************************************************************** //This file is part of "arith_large_cgi", a program that is designed to be //invoked by a PHP script as part of serving a web page that performs //calculations involving large integers. (A secondary compiled program is //used because a compiled program can perform certain calculation-intensive //tasks far more efficiently than a PHP script.) This program is provided by //David T. Ashley (dashley@gmail.com) under the MIT License (reproduced //immediately below). //******************************************************************************** //Permission is hereby granted, free of charge, to any person obtaining a copy //of this software and associated documentation files (the "Software"), to deal //in the Software without restriction, including without limitation the rights //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //copies of the Software, and to permit persons to whom the Software is //furnished to do so, subject to the following conditions: // //The above copyright notice and this permission notice shall be included in all //copies or substantial portions of the Software. // //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //SOFTWARE. //******************************************************************************** // //Sieve of Eratosthenes Table Generation //-------------------------------------- //This utility generates a sieve table used in trial division prime number factorization. //The table is a table of differentials to be added to trial divisors. //-------------------------------------------------------------------------------- #include #define NAMING_PREFIX "SUBFUNC_PFACT_" #define SIEVE_SIZE (2310) /* 2 * 3 * 5 * 7 * 11 */ unsigned int pfacts[] = {2, 3, 5, 7, 11}; unsigned int sieve_table_a[SIEVE_SIZE]; char *output_header[] = { "//This file is an automatically-generated sieve table, generated by the", "//program \"sieve_gen.c\".", "//", NULL }; char *output_footer[] = { "//", "//End of automatically-generated file.", NULL }; int main(int argc, char *argv[]) { int i, j; unsigned p, q; unsigned current_factor; char **cptr; //Initialize the sieve table. */ for (i=0; i < SIEVE_SIZE; i++) { sieve_table_a[i] = 1; } /* For each prime component, mark off all multiples. */ for (i=0; i