##### From the Gapcoin-PoWCore README

The average length of a prime gap with the starting prime $p$, is $log(p)$, which means that the average prime gap size increases with larger primes. Instead of the pure length, Gapcoin uses the *merit* of a prime gap, which is the ratio of the gap’s size to the average gap size. Let $p$ be the prime starting a prime gap, then $m\; =\; gapsize/log(p)$ will be the *merit* of this prime gap.

Also a pseudo random number is calculated from $p$ to provide finer difficulty adjustment. Let $rand(p)$ be a pseudo-random function with $0\; <\; rand(p)\; <\; 1$. Then, for a prime gap starting at prime $p$ with size $s$, the difficulty will be $s/log(p)\; +\; 2/log(p)\; \ast \; rand(p)$, where $2/log(p)$ is the average distance between a gap of size $s$ and $s\; +\; 2$ (the next greater gap) in the proximity of $p$.

When it actually comes to mining, there are two additional fields added to the block header, named “shift” and “adder”. We will calculate the prime $p$ as `sha256(block header) ∗ 2^shift + adder`

. As an additional criterion, the adder must be smaller than `2^shift`

to avoid the PoW being reused.