fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc= new Scanner(System.in);
  14.  
  15. int t=sc.nextInt();
  16. while(t-->0)
  17. {
  18. String s=sc.next();
  19. int n=Integer.parseInt(s);
  20. int root=(int)Math.sqrt(n);
  21. boolean flag=false;
  22. if(root*root==n)
  23. {
  24.  
  25. for(int a=99;a>=0;a--)
  26. {
  27.  
  28. int b=root-a;
  29. if(b>=0 && b<=99)
  30. {
  31. int sum=b+a;
  32.  
  33. if(sum*sum==n)
  34. {
  35. flag=true;
  36. System.out.println(a+" "+b);
  37. // break;
  38.  
  39. }
  40. }
  41.  
  42. }
  43.  
  44.  
  45. }
  46. if(!flag)
  47. System.out.println("-1");
  48. }
  49. }
  50. }
Success #stdin #stdout 0.19s 58792KB
stdin
5
0001
1001
1000
4900
2025
stdout
1 0
0 1
-1
-1
70 0
69 1
68 2
67 3
66 4
65 5
64 6
63 7
62 8
61 9
60 10
59 11
58 12
57 13
56 14
55 15
54 16
53 17
52 18
51 19
50 20
49 21
48 22
47 23
46 24
45 25
44 26
43 27
42 28
41 29
40 30
39 31
38 32
37 33
36 34
35 35
34 36
33 37
32 38
31 39
30 40
29 41
28 42
27 43
26 44
25 45
24 46
23 47
22 48
21 49
20 50
19 51
18 52
17 53
16 54
15 55
14 56
13 57
12 58
11 59
10 60
9 61
8 62
7 63
6 64
5 65
4 66
3 67
2 68
1 69
0 70
45 0
44 1
43 2
42 3
41 4
40 5
39 6
38 7
37 8
36 9
35 10
34 11
33 12
32 13
31 14
30 15
29 16
28 17
27 18
26 19
25 20
24 21
23 22
22 23
21 24
20 25
19 26
18 27
17 28
16 29
15 30
14 31
13 32
12 33
11 34
10 35
9 36
8 37
7 38
6 39
5 40
4 41
3 42
2 43
1 44
0 45