Rust | 0ms | beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n    pub fn prime_palindrome(n: i32) -> i32 {\n        let is_prime = |n: i32| -> bool {\n            if n == 1 {return false;}\n            if n == 2 {return true;}\n            if n & 1 == 0 {return false;}\n            let sqn = f64::sqrt(n as f64) as i32 + 1;\n            for i in (3..sqn).step_by(2) {\n                if n % i == 0 {\n                    return false;\n                }\n            }\n            true\n        };\n        if n < 3 {return 2;}\n        if n == 3 {return 3;}\n        if n <= 5 {return 5;}\n        if n <= 7 {return 7;}\n        if n <= 11 {return 11;}\n        let mut n = n;\n        while true {\n            for palindrome in PalindromeOddLenGen::new(n) {\n                if palindrome >= n && is_prime(palindrome) {\n                    return palindrome;\n                }\n            }\n            n *= 10;\n        }\n        -1\n    }\n    \n}\n\npub struct PalindromeOddLenGen {\n    start: i32,\n    end: i32,\n    middle: i32,\n}\n\nimpl PalindromeOddLenGen {\n    // all palindromes of even length are divisible by 11\n    fn new(n: i32) -> Self {\n        let ns = n.to_string();\n        let length = (ns.len()/2) as u32;\n        Self {\n            start: 10_i32.pow(length-1),\n            end: 10_i32.pow(length),\n            middle: 0,\n        }\n    }\n}\n\nimpl Iterator for PalindromeOddLenGen {\n    type Item = i32;\n\n    fn next(&mut self) -> Option<i32> {\n        if self.start >= self.end {\n            None\n        } else {\n            let result = get_palindrome(self.start, self.middle);\n            if self.middle == 9 {\n                self.middle = 0;\n                self.start += 1;\n            } else {\n                self.middle += 1;\n            }\n            result\n        }\n    }\n}\n\nfn get_palindrome(mut x: i32, y: i32) -> Option<i32> {\n    // all palindromes of even length are divisible by 11\n    let mut palindrome = x;\n    let mut rev = 0;\n    palindrome = palindrome * 10 + y;\n    while x > 0 {\n        palindrome *= 10;\n        rev = rev * 10 + x % 10;\n        x /= 10;\n    }\n    Some(palindrome + rev)\n}\n\n```
['Rust']