#P40002. 2019 ICPC NCNA Regional Contest C - New Maths
2019 ICPC NCNA Regional Contest C - New Maths
题目描述
“Drat!” cursed Charles. “This stupid carry bar is not working in my Engine! I just tried to calculate the square of a number, but it’s wrong; all of the carries are lost.”
“Hmm,” mused Ada, “arithmetic without carries! I wonder if I can figure out what your original input was, based on the result I see on the Engine.”
Carryless addition, denoted by ⊕, is the same as normal addition, except any carries are ignored (in base 10). Thus, 37⊕48 is 75, not 85.
where any or is considered zero if i>m or j>n. For example, 9⊗1234 is 98769876, 90⊗1234 is 9876098760, and 99⊗1234 is 9753697536.
输入格式
The input consists of a single line with a positive integer N, with at most 25 digits and no leading zeros
输出格式
Print, on a single line, the least positive number aa such that a⊗a=N. If there is no such a, print ‘-1’ instead.
样例
输入样例1
6
输出样例1
4
输入样例2
149
输出样例2
17
输入样例3
123476544
输出样例3
11112
输入样例4
15
输出样例4
-1