def search_palindromic_weak_prime(nlow, nhigh):
    n = nlow
    if (not isprime(n)):
        n = nextprime(n)
    while (n < nhigh):
        if check_weak_prime(n):
            print('Weak prime = ', n)
            n2 = int(str(n)[::(- 1)])
            if check_weak_prime(n2):
                print('Solution found:')
                print('   n = ', n)
                print('   n2 = ', n2)
                return True
        n = nextprime(n)
    return False
def search_palindromic_weak_prime(nlow, nhigh):
    n = nlow
    if (not isprime(n)):
        n = nextprime(n)
    while (n < nhigh):
        if check_weak_prime(n):
            print('Weak prime = ', n)
            n2 = int(str(n)[::(- 1)])
            if check_weak_prime(n2):
                print('Solution found:')
                print('   n = ', n)
                print('   n2 = ', n2)
                return True
        n = nextprime(n)
    return False