Skip to content

Commit 25010c4

Browse files
authored
Merge pull request #1942 from AlgorithmWithGod/LiiNi-coder
[20260217] BOJ / G5 / 다이어트 / 이인희
2 parents 7ca72a3 + 5169f33 commit 25010c4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
public class Main {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
int G = Integer.parseInt(br.readLine());
10+
long old = 1;
11+
long now = 2;
12+
boolean isFind = false;
13+
14+
while (now <= 100000 && old < now) {
15+
long diff = now * now - old * old;
16+
if (diff == G) {
17+
System.out.println(now);
18+
isFind = true;
19+
old++;
20+
} else if (diff < G) {
21+
now++;
22+
} else {
23+
old++;
24+
}
25+
}
26+
27+
28+
if (!isFind) {
29+
System.out.println(-1);
30+
}
31+
}
32+
}
33+
34+
```

0 commit comments

Comments
 (0)