Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 300 点
問題文
整数 N が与えられます。 3^A + 5^B = N を満たす正の整数の組 (A, B) が存在するか判定し、存在する場合は 1 組求めてください。
制約
- 1 \leq N \leq 10^{18}
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
条件を満たす組 (A, B) が存在しない場合は -1
と出力せよ。
存在する場合は A と B を空白区切りで出力せよ。答えが複数存在する場合はどれを出力してもかまわない。
入力例 1
106
出力例 1
4 2
3^4 + 5^2 = 81 + 25 = 106 なので、(A, B) = (4, 2) は条件を満たします。
入力例 2
1024
出力例 2
-1
入力例 3
10460353208
出力例 3
21 1
Score : 300 points
Problem Statement
Given is an integer N. Determine whether there is a pair of positive integers (A, B) such that 3^A + 5^B = N, and find one such pair if it exists.
Constraints
- 1 \leq N \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
If there is no pair (A, B) that satisfies the condition, print -1
.
If there is such a pair, print A and B of one such pair with space in between. If there are multiple such pairs, any of them will be accepted.
Sample Input 1
106
Sample Output 1
4 2
We have 3^4 + 5^2 = 81 + 25 = 106, so (A, B) = (4, 2) satisfies the condition.
Sample Input 2
1024
Sample Output 2
-1
Sample Input 3
10460353208
Sample Output 3
21 1