// ---------------------------------------------------------------------- // // Module: smooth.cc // Description: generate small modular squares and factor them. // Contributed by: Rene Peralta // Date: Nov. 2003 // // ---------------------------------------------------------------------- #include #include "small_primes.h" #include #define B 7 #define SMALL 100 #define max_factors 100 #define B_SIZE 4 int test_smoothness( void ); ln getN( void ); ln modulus; ln X; ln Y; int main() { using ::modulus; int num_smooths = 0; ln the_square; modulus = getN( ); X = Sqrt(modulus); while (num_smooths < B_SIZE + 10) { X++; the_square = X*X % modulus; if (the_square > SMALL ) continue; cout << the_square <<" is a small square" << endl; if (test_smoothness()) num_smooths++; } } int test_smoothness( ) { using ::modulus; int primefactor[100]; int index = 1; int fn; Y = X*X % modulus; for(int i = 0; i < max_factors; i++) primefactor[i] = 0; fn = 0; while (Y > 1) { while ((Y % Prime[index]) == 0) { primefactor[fn] = Prime[index]; fn++; Y = Y/Prime[index]; } index++; if (Prime[index] > B) break; } if (Y == 1) { fn = 0; while (primefactor[fn] > 0) { cout << primefactor[fn] << " "; fn++; } cout << " = " << X << " squared mod " << modulus << endl; return(1); } return(0); } ln getN( void ) { ln n; cout << "input a positive integer (0 to exit)" << endl; cin >> n ; cout << endl << endl; if (n == 0) { cout << "bye " << endl; exit( 0 ); } if( n.IsNegative( ) ) { cout << -1 << endl; n = -n; } return n; }