103432: [Atcoder]ABC343 C - 343

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:13 Solved:0

Description

Score: $250$ points

Problem Statement

You are given a positive integer $N$.

Find the maximum value of a palindromic cube number not greater than $N$.

Here, a positive integer $K$ is defined to be a palindromic cube number if and only if it satisfies the following two conditions:

  • There is a positive integer $x$ such that $x^3 = K$.
  • The decimal representation of $K$ without leading zeros is a palindrome. More precisely, if $K$ is represented as $K = \sum_{i = 0}^{L-1} A_i10^i$ using integers $A_0, A_1, \ldots, A_{L-2}$ between $0$ and $9$, inclusive, and an integer $A_{L-1}$ between $1$ and $9$, inclusive, then $A_i = A_{L-1-i}$ for all $i = 0, 1, \ldots, L-1$.

Constraints

  • $N$ is a positive integer not greater than $10^{18}$.

Input

The input is given from Standard Input in the following format:

$N$

Output

Print the answer.


Sample Input 1

345

Sample Output 1

343

$343$ is a palindromic cube number, while $344$ and $345$ are not. Thus, the answer is $343$.


Sample Input 2

6

Sample Output 2

1

Sample Input 3

123456789012345

Sample Output 3

1334996994331

Input

Output

得分:250分

问题描述

给你一个正整数$N$。

找出不大于$N$的最大回文立方数。

这里,正整数$K$定义为回文立方数,当且仅当它满足以下两个条件:

  • 存在一个正整数$x$,使得$x^3=K$。
  • $K$的十进制表示法中,不包括前导零,是一个回文数。更精确地说,如果$K$可以用整数$A_0,A_1,\ldots,A_{L-2}$表示,其中$A_0,A_1,\ldots,A_{L-2}$在$0$到$9$之间,包括$0$和$9$,以及一个整数$A_{L-1}$在$1$到$9$之间,包括$1$和$9$,则对于所有$i=0,1,\ldots,L-1$,$A_i=A_{L-1-i}$。

约束条件

  • $N$是一个不大于$10^{18}$的正整数。

输入

输入从标准输入按以下格式给出:

$N$

输出

输出答案。


样例输入1

345

样例输出1

343

$343$是一个回文立方数,而$344$和$345$不是。因此,答案是$343$。


样例输入2

6

样例输出2

1

样例输入3

123456789012345

样例输出3

1334996994331

加入题单

算法标签: