Ultra fast solution, beat 99%, no string manipulation
\nclass Solution {\npublic:\n    char notprime[15000]={0};\n    vector<int> primes;\n    // pow10(i) == 10^i\n    int pow10[9];\n    \n    Solution(){\n        
```\nclass Solution {\npublic:\n    char notprime[15000]={0};\n    vector<int> primes;\n    // pow10(i) == 10^i\n    int pow10[9];\n    \n    Solution(){\n        primes.push_back(2);\n        for (int i=3;i < 15000;i+=2){\n            if (notprime[i]) continue;\n            primes.push_back(i);\n            for (int j=i+i; j < 15000; j+=i)\n                notprime[j] = 1;\n        }\n        \n        for (int i=0, d=1;i<9;i++, d*=10){\n            pow10[i]=d;\n        }\n    }\n    \n    int revdigits(int a, int ndigits){\n        int b = 0;\n        while (ndigits--){\n            b = b*10 + a%10;\n            a /= 10;\n        }\n        return b;\n    }\n    \n    bool isprime(int a){\n        int limit = ceil(sqrt(a));\n        for (int i=0 ; i < primes.size() && primes[i] <=limit ;i++)\n            if (a%primes[i] == 0)\n                return false;\n        return true;\n    }\n    \n    inline int numdigits(int a){\n        return floor(1+ log10(a));\n    }\n    \n    // ndigits: number of digits in "a"\n    inline int makepalin(int a,int ndigits, bool even){\n         if (even){\n             return a * pow10[ndigits] + revdigits(a,ndigits);\n         }\n         return a * pow10[ndigits-1] + revdigits(a/10,ndigits-1);\n    }\n    \n    int primePalindrome(int N) {\n        if (N <= 2) return 2;\n        \n        for (int nd = numdigits(N); ; nd ++){\n            int first = pow10[(nd-1)/2];\n            int last = pow10[(nd-1)/2+1] ;\n            for (int i= nd==numdigits(N)? N / pow10[nd/2] : first; i < last;i++){\n                // check whether start with even digit, if so, \n                // it will also end with even digit, hence skip to the next batch \n                if ((i/first) % 2 == 0) {\n                    i += first-1;\n                    continue;\n                }\n                // make palindrome of length "nd"\n                int palin=makepalin(i, (nd+1)/2, nd%2==0);\n                if (palin >= N && isprime(palin)) return palin;\n            }\n        }\n\n        return 0;\n    }\n};\n```
[]