Prime Factorization and Debugging Macros
This program was written in response to a problem posted on projecteuler.net. Please note that is is NOT a solution to the problem, projecteuler asks that the solutions not be posted.
I wrote this program to demonstrate three things
- Determining prime numbers using the Sieve of Eratosthenes
- Using that sieve to find the prime factors of a number
- Showcase some C++ debugging macros I wrote.
I was intentionally rather sparse in writing comments for the program, preferring to think that its functioning is self-evident.
If you don't think so, please, please, please write me with constructive suggestions at
showprimes number [number ...]
displays, in debugging messages, the prime factorization of number(s), both factors and exponent (number of times that factor occurs).
I've included my C++ debugging macro file. It's purpose is to make it simple to print values of variables in a uniform format.
The basic macro, DB prints the variable and its value. For example
the statement DB(var) would print var=value when it was executed.
There are variations of that macro to print 2, 3, 4, and more variable values
on the same line (DB2, DB3, DB4, etc.).
Because this program demonstrates the debugging macros the output is not very pretty. LOUD and be #defined to display the extra information printed that I used for debugging during development.
david@godel: showprimes 6883727711
6883727711 = 7**3 * 359**1 * 55903**1
I compiled and ran this program on my personal system. Because it is my personal system I placed the header file ydebug.hpp in the ⁄usr⁄include directory so that I could include it in programs with the statement
#include <ydebug.h> and it would not matter which directory housed the source program
If you want to compile it without modifying usr⁄include change the line above to
#include "ydebug.h" and put the file ydebug.h in the same directory as the source file.