I explore patterns in prime numbers as a hobby. The most satisfying part of this project happened in Excel.

For each candidate number, I divided it by every prime smaller than it and added up the remainders. Then I subtracted the previous candidate’s total from the current one. In the range I tested, the resulting differences showed a pattern that made the primes easy to spot in my spreadsheet.

I thought of each remainder as a clock. With division by 3, for example, the remainder goes 0, 1, 2, then back to 0 as you move through consecutive integers. Every reset marks a multiple of 3. I wanted to see what would happen if I kept clocks only for prime divisors.

I brought the spreadsheet idea to ChatGPT, which wrote the C implementation. The program, Prime Clock Sieve, uses a segmented sieve and marks composites where the clocks would reset. It generates primes in ascending order and writes one per line.

Writing primes to a file

On my Windows PC, using one thread, I compared the time to generate the primes, format them as decimal text, and write them to a file.

Upper limit Prime Clock Sieve 013 primesieve 12.18
100 million 70.68 ms 361.48 ms
1 billion 0.574 s 3.434 s

In a separate check, the complete prime list up to 10 billion matched the reference output byte for byte.

This is my first project on GitHub. The Prime Clock Sieve repository includes the C source, a Windows executable, and the benchmark results. If you try the file-output benchmark on your machine, I’d be curious to see how the timings compare.

The Excel experiment and the idea of using prime-period clocks were mine. ChatGPT wrote the C implementation and drafted the English article from my account and the project benchmarks.