Problem: Find the largest prime palindrome less than a given number.

Write a Python function largest_prime_palindrome(n) that takes an integer n as input and returns the largest prime palindrome that is less than n. A prime palindrome is a number that is both prime and a palindrome (reads the same forwards and backwards).

Your solution should be efficient and optimized for large values of n.

Here's an example of how the function should behave:

"""
>>> largest_prime_palindrome(100)
97

>>> largest_prime_palindrome(1000)
929

>>> largest_prime_palindrome(10000)
9931
"""
Note that the largest prime palindrome less than 100 is 97, less than 1000 is 929, and less than 10000 is 9931.