問題一覧 > 通常問題

No.1458 Segment Function

レベル : / AI推定難易度 : 825 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 76
作問者 : hiikunZ / テスター : shiomusubi496
お気に入りにしたユーザー ProblemId : 6100 / 自分の提出
問題文最終更新日: 2021-03-30 12:02:05
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
新入生プログラミングコンテスト 2021(夜の部) (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。