20ms C++ solution
find the first palindrome number by N++;\n2. return if prime, or generate the next palindrome\n\nhere is the way to generate number:\n1. start from the inner po
1. find the first palindrome number by N++;\n2. return if prime, or generate the next palindrome\n\nhere is the way to generate number:\n1. start from the inner position, like number `3` in `123321` and `12321`;\n2. if the number<9, add it, like `123321` -> `124421` or `12321` -> `12421`;\n3. find < 9 number, like `2` in  `12999921`and add it, remember calculate the step careful\n4. if all is 9, like `9999`, just add `2` and get `10001`\n\nthe following is my code\n```\nclass Solution {\npublic:\n    bool isPal(int x) {\n        int reverse = 0, src = x;\n        while (x) {\n            reverse = reverse * 10 + x % 10;\n            x /= 10;\n        }\n        return reverse == src;\n    }\n    \n    int nextPal(int x) {\n        int n = 0, m, tmp;\n        while(pow(10, n) <= x) n ++;\n        for (m = (n - 1) / 2; m >= 0; m --) {\n            tmp = x / (int)pow(10, m) % 10;\n            if (tmp < 9) {\n                if (n % 2 && m == (n-1)/2) return x + pow(10, m);\n                return x + pow(10, m+1) + pow(10, m);\n            }\n        }\n        return x + 2;\n    }\n    \n    bool isPrime(int x) {\n        if (x < 2) return false;\n        int s = sqrt(x);\n        for (int i = 2; i <= s; i ++) {\n            if (x % i == 0) return false;\n        }\n        return true;\n    }\n    \n    int primePalindrome(int N) {\n        while (!isPal(N)) N ++;\n        while(!isPrime(N)) N = nextPal(N);\n        return N;\n    }\n};\n```
[]