問題一覧 > 教育的問題

No.2271 13-Digit Precision Approximation of Square Roots

レベル : / AI推定難易度 : 1850 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 18
作問者 : 👑 p-adic / テスター : 👑 qand
お気に入りにしたユーザー ProblemId : 8608 / 自分の提出
問題文最終更新日: 2023-04-14 22:43:28
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
yukicoder contest 384 (順位表) の他の問題:

Problem Statement

An integer $N$ and a non-negative integer $E$ are given as input.

 

First, we introduce some terminology. For an integer $n$ other than $0$, $v_5(n)$ denotes its $5$-adic additive valuation (the number of times $n$ is divisible by $5$). For integers $n_0$ and $n_1$, their $5$-adic distance $d_5(n_0,n_1)$ is defined as follows:

$\displaystyle d_5(n_0,n_1) = \left\{ \begin{array}{ll} \displaystyle 5^{- v_5(n_0 - n_1)} &\displaystyle (n_0 \neq n_1) \\ \displaystyle 0 &\displaystyle (n_0 = n_1) \\ \end{array} \right. $

For an integer $n$ and a non-negative integer $e$, an $e$-digit precision $5$-adic approximation of the square root of $n$ is an integer $r$ satisfying $d_5(n,r^2) \leq 5^{-e}$.

 

Determine whether there exists an $E$-digit precision $5$-adic approximation $r$ of the square root of $N$ satisfying $- 2^{29} \leq r \leq 2^{29}$, and if one exists, find $1$ such $r$.

Input

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

Constraints

The input satisfies the following constraints:

  • $N$ is an integer satisfying $- 2^{29} \leq N \leq 2^{29}$
  • $E$ is an integer satisfying $0 \leq E \leq 13$

Output

If there exists an $E$-digit precision $5$-adic approximation $r$ of the square root of $N$ satisfying $- 2^{29} \leq r \leq 2^{29}$, print $1$ such $r$ on $1$ line; if none exists, print NaN.

This is a special judge problem. The correct output may not be unique.

Print a newline at the end.

Sample

Sample 1
Input
0
0
Output
0

$\displaystyle d_5(0,0^2) = 0 \leq 1 = 5^{-0} $

Therefore, $0$ is a $0$-digit precision $5$-adic approximation of the square root of $0$.

Sample 2
Input
1
1
Output
1

$\displaystyle d_5(1,1^2) = 0 \leq 5^{-1} $

Therefore, $1$ is a $1$-digit precision $5$-adic approximation of the square root of $1$. Other outputs such as $-1$ and $6$ are also correct.

Sample 3
Input
2
1
Output
NaN

There is no $1$-digit precision $5$-adic approximation of the square root of $2$.

Sample 4
Input
-1
1
Output
2

$\displaystyle d_5(-1,2^2) = 5^{-v_5(-5)} = 5^{-1} $

Therefore, $2$ is a $1$-digit precision $5$-adic approximation of the square root of $-1$.

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