#2396

Strictly Palindromic Number

pupil · 430 · lc medium +25 · verified · 90.3% accepted · 821 likes · top 99%

Description

An integer n is strictly palindromic if its representation in every base b from 2 to n - 2 inclusive reads as a palindrome.

Given an integer n, return true if it is strictly palindromic, or false otherwise.

Example 1:

Input: n = 9
Output: false
Explanation: In base 2: 9 = 1001 (base 2), which is palindromic.
In base 3: 9 = 100 (base 3), which is not palindromic.
Therefore, 9 is not strictly palindromic so we return false.
Note that in bases 4, 5, 6, and 7, n = 9 is also not palindromic.

Example 2:

Input: n = 4
Output: false
Explanation: We only consider base 2: 4 = 100 (base 2), which is not palindromic.
Therefore, we return false.

Code

1
2
3