P25331 [AtCoder] Base N
普及-
题目描述

Problem Description

For an integer $ N $ greater than or equal to $ 10 $, let $ f(N) $ be the number that can be represented as $ N $ in base $ N $.

For example, $ f(23) $ can be calculated as $2 \times 23 + 3 = 49$.

Given an integer $ A $, we want to determine if this number can be represented in the form of $ f(k) $.

If the integer $ A $ can be represented using an integer $ k $ greater than or equal to $ 10 $ in the form of $ f(k) $, output $ k $. Otherwise, output $ -1 $.

Input Format

The input is given from the standard input in the following format:

$ A $

  • The first line contains an integer $A (1 \leq A \leq 10^{16})$.

Output Format

If the integer $ A $ can be represented using an integer $ k $ greater than or equal to $ 10 $ in the form of $ f(k) $, output $ k $. Otherwise, output $ -1 $. End your output with a newline.

Sample Input and Output

Sample Input #1

49

Sample Output #1

23

Sample Input #2

999999999999999

Sample Output #2

-1

Sample Input #3

10000000000000000

Sample Output #3

10000

Notes/Hints

Sample Explanation 1

As given in the sample.

Sample Explanation 2

Large inputs may be given.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
49
样例输出
23