File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ int G = Integer . parseInt(br. readLine());
9+
10+ long low = 1 ;
11+ long high = 2 ;
12+ boolean found = false ;
13+ StringBuilder sb = new StringBuilder ();
14+
15+ while (true ) {
16+ long diff = high * high - low * low;
17+
18+ if (high - low == 1 && diff > G ) break ;
19+
20+ if (diff == G ) {
21+ sb. append(high). append(" \n " );
22+ found = true ;
23+ high++ ;
24+ } else if (diff < G ) {
25+ high++ ;
26+ } else {
27+ low++ ;
28+ }
29+ }
30+
31+ if (! found) {
32+ System . out. println(- 1 );
33+ } else {
34+ System . out. print(sb. toString());
35+ }
36+ }
37+ }
38+ ```
You can’t perform that action at this time.
0 commit comments