Skip to content

innomation/Riemann-Says

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Prime Number Pattern Analyzer

C++ Version License

A high-performance C++ command-line tool for analyzing large files of prime numbers to uncover fascinating mathematical patterns and statistics.


Why This Project?

The distribution of prime numbers is one of the most enduring mysteries in mathematics. While their sequence seems random, it contains beautiful and subtle patterns. This project provides a fast, memory-efficient tool to explore these patterns within a given list of primes.

Whether you're a student, a math enthusiast, or a researcher generating your own prime number sets, this analyzer allows you to quickly calculate statistics on prime constellations, discover the largest gaps between primes, and analyze the distribution of their final digits.

Features

This tool reads a file containing one prime number per line and calculates the following statistics:

  • Prime Constellations:
    • Twin Primes: Counts pairs of primes with a gap of 2 (e.g., 11, 13).
    • Cousin Primes: Counts pairs of primes with a gap of 4 (e.g., 13, 17).
    • Sexy Primes: Counts pairs of primes with a gap of 6 (e.g., 17, 23).
  • Maximum Prime Gap: Identifies the largest gap found between any two consecutive primes in the list and reports the two primes that form this gap.
  • Last Digit Distribution: Calculates the frequency of primes ending in the digits 1, 3, 7, and 9 (the only possible last digits for primes greater than 5).
  • Memory Efficient: Processes files of any size by reading them line-by-line, consuming minimal RAM.

Getting Started

Prerequisites

  • A C++ compiler that supports the C++20 standard (for std::format).
  • A text file containing prime numbers, with one prime per line. This file must be named primes.txt and placed in the same directory as the executable.

How to Compile and Run

  1. Save the Code: Save the C++ source code as main.cpp.

  2. Prepare Your Primes File: Ensure you have a file named primes.txt in the same directory. It should look like this:

    2
    3
    5
    7
    11
    ...
    
  3. Compile the Program: Open a terminal and compile the code using a C++20 compatible compiler.

    g++ -std=c++20 -o prime_analyzer main.cpp
  4. Run the Analyzer: Execute the compiled program from your terminal.

    ./prime_analyzer

The program will then analyze primes.txt and print a detailed report to your console.

Example Output

--- Prime Number Analysis Report --- Total primes analyzed: 78498

--- Prime Constellations --- Twin Primes (gap of 2): 8169 pairs Cousin Primes (gap of 4): 8142 pairs Sexy Primes (gap of 6): 16390 pairs

--- Prime Gaps --- Largest gap found: 72 Between 31397 and 31469 --- Last Digit Distribution --- Ending in 1: 19612 primes Ending in 3: 19632 primes Ending in 7: 19641 primes Ending in 9: 19610 primes

Contributing

Contributions are welcome! If you have ideas for new patterns to analyze, performance improvements, or bug fixes, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Having programatic fun with prime numbers!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published