Sobes.tech
Junior — Senior

Number-palindrome in all numeral systems from 2 to n-2

livecode

Task condition

Given an integer number. It is said that a number is strictly palindromic if its representation is a palindrome in all numeral systems from 2 up to number‑2 inclusive. A palindrome is a sequence of digits that reads the same from left to right and from right to left. The task is to determine whether number satisfies this condition. The function should return true if the number is strictly palindromic, and false otherwise.

Example 1:

  • Input: number = 9
  • Output: false
  • Explanation:
    • System 2: 9 → "1001" (palindrome)
    • System 3: 9 → "100" (not a palindrome)
    • System 4: 9 → "21" (not a palindrome)
    • System 5: 9 → "14" (not a palindrome)
    • System 6: 9 → "13" (not a palindrome)
    • System 7: 9 → "12" (not a palindrome) Since in some systems the representation is not a palindrome, return false.

Example 2:

  • Input: number = 4
  • Output: false
  • Explanation:
    • System 2: 4 → "100" (not a palindrome)
    • The range of numeral systems: from 2 to 2 (number‑2 = 4‑2) The representation in the only checked system is not a palindrome, so the result is false.