The prime numbers are not regularly spaced. For example from `2` to `3` the step is `1`.
From `3` to `5` the step is `2`. From `7` to `11` it is `4`.
Between 2 and 50 we have the following pairs of 2-steps primes:

`3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43`

We will write a function `step` with parameters:

- `g` (integer >= 2) which indicates the step we are looking for,

- `m` (integer >= 2) which gives the start of the search (m inclusive),

- `n` (integer >= m) which gives the end of the search (n inclusive)

In the example above `step(2, 2, 50)` will return `[3, 5]` which is the first pair between 2 and 50 with a 2-steps.

So this function should return the **first** pair of the two prime numbers spaced with a step of `g`
between the limits `m`, `n` if these g-steps prime numbers exist otherwise `nil` or `null` or `None` or `Nothing` or `[]` or `"0, 0"` or `{0, 0}` or `0 0`(depending on the language). 


#Examples:

- 


`step(2, 5, 7) --> [5, 7] or (5, 7) or {5, 7} or "5 7"`

`step(2, 5, 5) --> nil or ... or [] in Ocaml or {0, 0} in C++`

`step(4, 130, 200) --> [163, 167] or (163, 167) or {163, 167}`

- **See more examples for your language in "RUN"**


- Remarks:

([193, 197] is also such a 4-steps primes between 130 and 200 but it's not the first pair).

`step(6, 100, 110) --> [101, 107]` though there is a prime between 101 and 107 which is 103; the pair 101-103 is a 2-step.


#Notes: 
The idea of "step" is close to that of "gap" but it is not exactly the same. For those interested they can have a look
at . 

A "gap" is more restrictive: there must be no primes in between 
(101-107 is a "step" but not a "gap". Next kata will be about "gaps":-).

For Go: nil slice is expected when there are no `step` between m and n.
Example: step(2,4900,4919) --> nil

Difficulty: EASY
Tags: Number theory

Mathematics

Starter code:
def step(g, m, n):
	

Solutions:
import math

def isPrime(n):
	if n <= 1:
		return False
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			return False
	return True

def step(g, m, n):
	if m >= n:
		return []
	else:
		for i in range(m, n + 1 - g):
			if isPrime(i) and isPrime(i + g):
				return [i, i + g]


def prime(number):
	if number < 2:
		return False
	elif number == 2:
		return True
	elif number % 2 == 0:
		return False
	for i in range(3, int(number ** 0.5) + 1, 2):
		if number % i == 0:
			return False
	return True

def step(g, m, n):
	res = []
	i = m
	while i <= n - g:
		if prime(i) and prime(i + g):
			res.append(i)
			res.append(i + g)
			return res
		i += 1
	return None


def is_prime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def step(g, m, n):
	for i in range(m, n - g):
		if is_prime(i) and is_prime(i + g):
			return [i, i + g]
	return None


step = lambda g, m, n, A=lambda x: all((x % i for i in range(2, int(x ** 0.5) + 1))): next(([i, i + g] for i in range(m, n + 1) if A(i) and i + g < n and A(i + g)), None)


import math

def step(g, m, n):

	def prime(n):
		if n >= 2:
			for i in range(2, int(math.sqrt(n)) + 1):
				if not n % i:
					return False
		else:
			return False
		return True
	for i in range(m, n - g):
		if prime(i + g) and prime(i):
			return [i, i + g]


def step(g, m, n):
	return next(([a, a + g] for a in range(m, n - g + 1) if is_prime(a) and is_prime(a + g)), None)

def is_prime(n):
	factors = 0
	for k in (2, 3):
		while n % k == 0 and factors < 2:
			n //= k
			factors += 1
	k = 5
	step = 2
	while k * k <= n and factors < 2:
		if n % k:
			k += step
			step = 6 - step
		else:
			n //= k
			factors += 1
	if n > 1:
		factors += 1
	return factors == 1


def step(g, m, n):

	def is_prime(n):
		if n == 2:
			return True
		elif n < 2 or n % 2 == 0:
			return False
		else:
			import math
			root = math.floor(math.sqrt(n))
			trial_factor = 3
			while trial_factor <= root:
				if n % trial_factor == 0:
					return False
				trial_factor += 2
			return True
	dic = {}
	current_prime = None
	for i in range(m, n + 1):
		if is_prime(i):
			current_prime = i
			if current_prime - g in dic:
				return [current_prime - g, current_prime]
			else:
				dic[current_prime] = True
	return None


def prime(n):
	for i in range(2, 1000):
		if i != n and n % i == 0:
			return False
	return True

def step(g, m, n):
	for num in range(m, n + 1):
		if prime(num) and prime(num + g) and (num + g <= n):
			return [num, num + g]
	return None


import itertools
compress = itertools.compress

def sieve(n):
	r = [False, True] * (n // 2) + [True]
	(r[1], r[2]) = (False, True)
	for i in range(3, int(n ** 0.5) + 1):
		if r[i]:
			r[i * i::2 * i] = [False] * ((n + 2 * i - 1 - i * i) // (2 * i))
	r = list(compress(range(len(r)), r))
	if r[-1] % 2 == 0:
		return r[:-1]
	return r
primes = set(sieve(2 * 10 ** 7))
maxi = max(primes)

def step(g, m, n):
	for i in range(m, n + 1):
		if i > maxi or i + g > n:
			break
		if i in primes and i + g in primes:
			return [i, i + g]
	return None