A modular algorithm to spot out prime numbers up to a specified number using vectors.
cpp-prime-identifier is a collection of C++ programs demonstrating fundamental number theory algorithms and mathematical operations. It provides utilities for prime number identification, prime factorization, greatest common divisor calculation, and modular arithmetic operations.
The application uses a modular approach with separate files for different mathematical operations:
main.cpp: Entry point for the prime identification program
// Finds all prime numbers up to a user-specified limitprime-factorization.cpp: Decomposes numbers into prime factors
// Example: 60 → 2² × 3 × 5gcd.cpp: Calculates the Greatest Common Divisor
// Example: GCD(48, 18) = 6mod.cpp: Performs modular arithmetic operations
// Handles modular calculations efficiently- Prime Identification: Uses vector-based algorithms to efficiently identify all prime numbers up to a given limit
- Prime Factorization: Breaks down composite numbers into their constituent prime factors
- GCD Calculation: Implements efficient algorithms (likely Euclidean) for finding the greatest common divisor
- Modular Operations: Provides utilities for modular arithmetic computations
When identifying primes up to a limit N:
- Initialize a vector to store potential primes
- Apply an efficient sieving or trial division algorithm
- Store identified primes in the vector structure
- Output results to the user
- STL Vectors: Dynamic array usage for storing primes
- Modular programming: Separation of concerns across multiple files
- Algorithm efficiency: Optimized mathematical operations
- Function decomposition: Breaking problems into reusable components
- Mathematical algorithms: Classical number theory implementations
- Clone the repository:
git clone https://github.com/achille010/cpp-prime-identifier.git
cd cpp-prime-identifier- Compile the program:
g++ -o prime_identifier main.cpp prime-factorization.cpp gcd.cpp mod.cpp- Run the executable:
./prime_identifier# Input: 20
# Output: 2, 3, 5, 7, 11, 13, 17, 19# Input: 60
# Output: 2² × 3 × 5# Input: 48, 18
# Output: 6- Input validation may be minimal
- Large number handling depends on data types used
- No GUI interface (command-line only)
- Performance not optimized for extremely large numbers
This is designed to demonstrate fundamental number theory algorithms in C++.
- C++ compiler (g++, clang++, or MSVC)
- C++11 or higher
- Standard Template Library (STL)
Contributions are welcome! Feel free to fork this repository and submit pull requests for improvements.
MIT License - Read details from the LICENSE file
Built as a demonstration of number theory algorithms in C++