#P8813. [CSP-J 2022] 乘方

    ID: 9609 远端评测题 500ms 128MiB 尝试: 1 已通过: 1 难度: 1 上传者: 标签>模拟2022O2优化基础算法CSP-J 入门级

[CSP-J 2022] 乘方

Background

To simulate the scoring situation during a contest, the time limit of this problem is reduced by 50%50\%.

Problem Description

Xiaowen has just started learning competitive programming. One day, she ran into this problem: given positive integers aa and bb, find the value of aba^b.

Here, aba^b means multiplying aa by itself bb times. For example, 232^3 means multiplying three 22's together, and the result is 2×2×2=82 \times 2 \times 2 = 8.

“So easy!” Xiaowen thought, and she quickly wrote a program. However, it produced an error during testing.

Xiaowen soon realized that all variables in her program were of type int. On most machines, the largest number that int can represent is 23112^{31} - 1, so once the computed result exceeds this number, her program will fail.

Since Xiaowen has just learned programming, she worries that using int might cause problems. Therefore, she wants you to output -1 as a warning when the value of aba^b exceeds 109{10}^9; otherwise, output the correct value of aba^b.

However, Xiaowen still does not know how to implement this program, so she asks you for help.

Input Format

The input consists of one line with two positive integers a,ba, b.

Output Format

Output one line: if aba^b does not exceed 109{10}^9, output aba^b; otherwise output -1.

10 9

1000000000

23333 66666

-1

Hint

For 10%10\% of the testdata, it is guaranteed that b=1b = 1.
For 30%30\% of the testdata, it is guaranteed that b2b \le 2.
For 60%60\% of the testdata, it is guaranteed that b30b \le 30, and ab1018a^b \le {10}^{18}.
For 100%100\% of the testdata, it is guaranteed that 1a,b1091 \le a, b \le {10}^9.

upd 2022.11.14/2025.04.02\text{upd 2022.11.14/2025.04.02}: One additional set of Hack\text{Hack} testdata has been added each time.

Translated by ChatGPT 5