Consider the number `1176` and its square (`1176 * 1176) = 1382976`. Notice that:

* the first two digits of `1176` form a prime.
* the first two digits of the square `1382976` also form a prime.
* the last two digits of `1176` and `1382976` are the same. 

Given two numbers representing a range (`a, b`), how many numbers satisfy this property within that range? (`a <= n < b`)


## Example

`solve(2, 1200) = 1`, because only `1176` satisfies this property within the range `2 <= n < 1200`. See test cases for more examples. The upper bound for the range will not exceed `1,000,000`. 

Good luck!

If you like this Kata, please try:

[Simple Prime Streaming](https://www.codewars.com/kata/5a908da30025e995880000e3)

[Alphabet symmetry](https://www.codewars.com/kata/59d9ff9f7905dfeed50000b0)

[Upside down numbers](https://www.codewars.com/kata/59f7597716049833200001eb)

Difficulty: introductory

Starter code:

def solve(a,b):
	

Solutions:
ls = ['11', '13', '17', '19', '23', '29', '31', '37', '41', '43', '47', '53', '59', '61', '67', '71', '73', '79', '83', '89', '97']
def solve(a,b):
    i = a
    s = 0
    while i < b:
        if (i*i-i)%100==0 and str(i)[:2] in ls and str(i*i)[:2] in ls:
            s += 1
        i += 1
    return s

from itertools import count

PRIMES     = ['11', '13', '17', '19', '23', '29', '31', '37', '41', '43', '47', '53', '59', '61', '67', '71', '73', '79', '83', '89', '97']
SET_PRIMES = set(PRIMES)
TAILS      = ['00', '01', '25', '76']        # 2 digits numbers that fulfill the condition 11(76)*11(76) = ...(76)

def solve(a,b):
    maxMissingDigits = len(str(b))-4
    matches = 0
    for nd in range(maxMissingDigits+1):
        for p in PRIMES:
            if nd == maxMissingDigits and int(p + '0'*(nd+2)) > b:                # All next generated numbers would be > b, so break
                break
            for t in TAILS:
                digs = count(0)
                while True:
                    d = ("{:0>"+str(nd)+"}").format(next(digs)) if nd else ''     # Digits to insert in the middle of the number
                    val = int(p+d+t)                                              # val = 2 digits prime + missing digits (up to maxMissingDigits) + 2 digits tail
                    if val > b or len(d) > nd: break                              # Generated value is too high or if the digits to insert exceed the current number of digits sought for, break
                    if str(val**2)[:2] in SET_PRIMES and a <= val:
                        matches += 1
                    if not d: break                                               # If no digits to insert, the loop has to be broken manually after its first iteration
    return matches

PRIMES = set([str(num) for num in range(3, 100) if all(num % x != 0 for x in [2] + list(range(3, int(num ** 0.5)+1, 2)))])

def solve(a, b):
  return sum(1 for x in range(max(a, 1000), b) if x % 100 == x*x % 100 and str(x)[:2] in PRIMES and str(x*x)[:2] in PRIMES)

from bisect import bisect_left, bisect

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

def is_symmetry(n):
    return str(n ** 2)[:2] in SPRIMES

SPRIMES = [str(i) for i in range(11, 100, 2) if is_prime(i)]
BASE = [i for i in range(0, 100) if (i*i) % 100 == i]
candidates = (
    i + d
    for i in range(1100, 10000000+1, 100)
    if str(i)[:2] in SPRIMES
    for d in BASE
)
NS = [x for x in candidates if is_symmetry(x)]


def solve(a, b):
    return bisect(NS, b-1) - bisect_left(NS, a)

two_digit_primes = set('11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97'.split())

# pregenerate eligible numbers
numbers = []
for n in range(11, 9799 +1):
    if str(n)[:2] in two_digit_primes:
        for ending in (0, 1, 25, 76):
            candidate = n*100 + ending
            if str(candidate**2)[:2] in two_digit_primes:
                numbers.append(candidate)
    
def solve(a, b):
    return sum(1 for n in numbers if a <= n < b)


from math import sqrt
def solve(a,b):
    i = a
    s = 0
    while i < b:
        if prope(i):
            s += 1
        i += 1
    return s

def prope(n):    
    return (n*n-n)%100==0 and prime(int(str(n)[:2])) and prime(int(str(n*n)[:2]))

def prime(n):
    if n == 2:
        return True
    i = 2
    while i< sqrt(n)+1:
        if n % i==0:
            return False
        i+=1
    return True

p = '11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97'.split()
li = [i for i in range(1,1000000) if str(i)[:2] in p and str(i*i)[:2] in p and str(i*i)[-2:]==str(i)[-2:]]
solve=lambda a,b:sum(1 for i in li if a<=i<=b)

def solve(a,b):
    a1 = (a + 99) // 100 * 100
    b1 = b // 100 * 100
    print((a1, b1))
    if a1 > b1: return sum(isok(x) for x in range(a, b))
    n = sum(isok(x) for x in range(a, a1)) + sum(isok(x) for x in range(b1, b))
    for k in range(a1, b1, 100):
        if str(k)[:2] in p2:
            for i in (0, 1, 25, 76):
                if str((k+i)**2)[:2] in p2:
                    n += 1
    return n

def isok(n):
    return n % 100 in (0, 1, 25, 76) and str(n)[:2] in p2 and str(n*n)[:2] in p2

p2 = '11', '13', '17', '19', '23', '29', '31', '37', '41', '43', '47', '53', '59', '61', '67', '71', '73', '79', '83', '89', '97'


primes = {11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}
endings = {'00','01','25','76'}

def solve(a,b):
    if b < 1176: return 0
    output = 0
    if a<1176: a=1176
    for i in [x for x in range(a,b) if str(x)[-2:] in endings]:
        if int(str(i)[:2]) not in primes:
            continue
        if int(str(i*i)[:2]) in primes:
            output += 1
    return output

def is_prime(n):
    if n<2:
        return False
    elif n==2:
        return True
    elif n%2==0:
        return False
    x=3
    while(x*x<=n):
        if n%x==0:
            return False
        x+=2
    return True

primes=set([x for x in range(1,100) if is_prime(x)])

def get_seq():
    r=[]
    for x in range(1,1000001):
        if int(str(x)[:2]) in primes:
            y=x*x
            if int(str(y)[:2]) in primes and str(x)[-2:]==str(y)[-2:]:
                r.append(x)
    return r
    
seq=set(get_seq())

def solve(a,b):
    r=0
    for x in range(a,b):
        if x in seq:
            r+=1
    return r