No.1458 Segment Function
タグ : / 解いたユーザー数 76
作問者 :
shiomusubi496
Problem Statement
For an integer $x$, define $f(x)$ as the number of segments that light up when $x$ is shown on a $7$-segment display without extra leading $0$s.
You are given an integer $P$ and a non-negative integer $N$.
When the operation of replacing $P$ with $f(P)$ is performed $N$ times,
what is the final value of $P$?
Let us state this precisely.
For an integer $x$, define $f(x)$ as follows.
\[\begin{equation}
f(x)= \left \{
\begin{array}{l}
6\ (x=0)\\
2\ (x=1)\\
5\ (x=2)\\
5\ (x=3)\\
4\ (x=4)\\
5\ (x=5)\\
6\ (x=6)\\
4\ (x=7)\\
7\ (x=8)\\
6\ (x=9)\\
f(floor(\frac{x}{10}))+f(x\ mod\ 10)\ (10\leq x)\\
1+f(-x)\ (x< 0)
\end{array}
\right.
\end{equation}
\]
Here, $floor(n)$ denotes the largest integer not exceeding $n$, and $m\ mod\ n$ denotes the remainder when $m$ is divided by $n$.
Then, define the sequence $A$ as follows.
\[\begin{equation}
\left\{
\begin{array}{l}
A_0=P\\
A_i=f(A_{i-1})\ (0< i)\\
\end{array}
\right.
\end{equation}
\]
You are given an integer $P$ and a non-negative integer $N$.
Find the value of $A_N$.
Constraints
- $-10^{200000}\leq P\leq 10^{200000}$
- $0\leq N\leq 10^{200000}$
- All input values are integers.
Input
The input is given in the following format.$P\ N$
Output
Print the answer on $1$ line.
Print a newline at the end.
Sample Input and Output
Sample 1
Sample Input 1
12 1
Sample Output 1
7
We have $A_0=12,\ A_1=f(A_0)=f(12)=f(floor(12/10))+f(12\ mod\ 10)=f(1)+f(2)=2+5=7$.
Sample 2
Input
-1 2
Output
5
We have $A_0=-1,\ A_1=f(A_0)=f(-1)=1+f(1)=1+2=3,A_2=f(A_1)=f(3)=5$.
Sample 3
Input
4 100
Output
4
$A_0,\ A_1,\ \dots ,\ A_{100}$ are all $\ 4\ $.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。