問題一覧 > 通常問題

No.1312 Snake Eyes

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 124
作問者 : fairy_lettuce / テスター : りあん
お気に入りにしたユーザー ProblemId : 5483 / 自分の提出
問題文最終更新日: 2020-12-09 23:35:34
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2020 (順位表) の他の問題:

This problem is the December 9 problem of yukicoder Advent Calendar Contest 2020.

Problem Statement

For a positive integer $N$ and an integer $p$ greater than or equal to $2$, we say that $N$ is a repdigit in base $p$ if all digits of $N$ are the same when it is written in positional notation in base $p$.
More precisely, $N$ is a repdigit in base $p$ if the remainders of $\lfloor N/{p^i} \rfloor$ divided by $p$ are all the same for all integers $i$ between $0$ and $\log_p{N}$, inclusive.
You are given a positive integer $N$ in decimal. Find the smallest $p$ such that $N$ is a repdigit in base $p$. It can be proved that such an integer $p$ greater than or equal to $2$ always exists.

Input

$N$

Constraints
  • $N$ is given as an integer in decimal.
  • $1\le N\le 10^{12}$

Output

Print in decimal the smallest $p$ such that $N$ is a repdigit in base $p$. Print a newline at the end.

Sample

Sample 1
Input
11
Output
10

$11_{(10)}$ is $1011_{(2)}$ in binary, $102_{(3)}$ in ternary, and so on, continuing with values that are not repdigits, and it first becomes a repdigit in decimal.

Sample 2
Input
25
Output
24

$25_{(10)}=11_{(24)}$. For every $p$ less than $24$, $25$ is not a repdigit in base $p$.

Sample 3
Input
129
Output
6

$129_{(10)}=333_{(6)}$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。