Under construction

Still being built. Things may change

Palindrome Numbers

Time limit1sMemory limit128 MB

Summary
Given a decimal integer with up to 1000 digits, print its representation in each base from 2 to 10 where it reads as a palindrome.
Level

Medium5 of 10

Topics
Math, String, Implementation
Solved
No attempts yet

Problem

A palindrome is a string that reads the same forwards and backwards. For example, ala and aa are palindromes, while adam is not.

Every integer can be written in base kk as (anan−1…a1a0)k(a_n a_{n-1} \dots a_1 a_0)_k, where each digit aia_i is an integer with 0≤ai<k0 \le a_i < k.

The value of (anan−1…a1a0)k(a_n a_{n-1} \dots a_1 a_0)_k is an⋅kn+an−1⋅kn−1+⋯+a1⋅k+a0a_n \cdot k^n + a_{n-1} \cdot k^{n-1} + \cdots + a_1 \cdot k + a_0. For example, the base-10 number 12310123_{10} has value 1⋅100+2⋅10+31 \cdot 100 + 2 \cdot 10 + 3, and the base-8 number 1238123_8 has value 1⋅64+2⋅8+31 \cdot 64 + 2 \cdot 8 + 3.

Given an integer nn in base 10, write a program that finds every base among 2,3,…,102, 3, \dots, 10 in which nn is a palindrome.

Input

The first line contains the integer nn. (1≤n≤1010001 \le n \le 10^{1000})

Output

If nn is not a palindrome in any of the bases 2,3,…,102, 3, \dots, 10, print NIE. Otherwise, for each base bb in which nn is a palindrome, print the base bb and the representation mm of nn in base bb on their own line, in the format b m. Print the bases in increasing order of bb.

Hint

For example, n=15n = 15 is 11111111 in base 2 and 3333 in base 4, so it is a palindrome in both. (1⋅23+1⋅22+1⋅2+1=3⋅4+3=151 \cdot 2^3 + 1 \cdot 2^2 + 1 \cdot 2 + 1 = 3 \cdot 4 + 3 = 15)

Examples3

  1. Example 1

    Input
    15
    
    Expected output
    2 1111
    4 33
    
  2. Example 2

    Input
    1
    
    Expected output
    2 1
    3 1
    4 1
    5 1
    6 1
    7 1
    8 1
    9 1
    10 1
    
  3. Example 3

    Input
    19
    
    Expected output
    NIE