-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccounting
More file actions
49 lines (40 loc) · 1.17 KB
/
Accounting
File metadata and controls
49 lines (40 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long A = sc.nextLong();
long B = sc.nextLong();
int n = sc.nextInt();
if (A == 0) {
System.out.println(B == 0 ? 0 : "No solution");
return;
}
if (B % A != 0) {
System.out.println("No solution");
return;
}
long Y = B / A;
if (Y == 0) {
System.out.println(0);
return;
}
long absY = Math.abs(Y);
long x = Math.round(Math.pow(absY, 1.0 / n));
for (long cand = Math.max(0, x - 1); cand <= x + 1; cand++) {
long val = 1;
for (int i = 0; i < n; i++) val *= cand;
if (val == absY) {
if (Y < 0) {
if (n % 2 == 0) {
System.out.println("No solution");
return;
}
cand = -cand;
}
System.out.println(cand);
return;
}
}
System.out.println("No solution");
}
}