No.1312 Snake Eyes
タグ : / 解いたユーザー数 124
作問者 :
りあん
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もしくは右上の雲マークをクリックしてアカウントを作成してください。