-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from AlgoLeadMe/31-SeongHoonC
31-SeongHoonC
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.lang.System.out; | ||
|
||
public class ๋ค์ด์ดํธ { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
long g = Integer.parseInt(br.readLine()); | ||
List<Integer> list = new ArrayList<Integer>(); | ||
int head = 2; | ||
int tail = 1; | ||
|
||
while (head >= tail && head < 987654321) { | ||
// ์ ๊ณฑ ๋นผ๊ธฐ ์ ๊ณฑ ๊ณ์ฐ ๊ฒฐ๊ณผ | ||
int x = (head + tail) * (head - tail); | ||
|
||
// g ๋ณด๋ค ํฌ๋ค๋ฉด tail ์ ์ฆ๊ฐ์ํด | ||
if (x > g) { | ||
tail++; | ||
continue; | ||
} | ||
|
||
// g ๋ณด๋ค ์๋ค๋ฉด head ๋ฅผ ์ฆ๊ฐ์ํด | ||
if (x < g) { | ||
head++; | ||
continue; | ||
} | ||
|
||
// g ๋ ๊ฐ์ผ๋ฉด ๋ฆฌ์คํธ์ ์ง์ด๋ฃ์ | ||
list.add(head); | ||
tail++; | ||
head++; | ||
} | ||
|
||
// ์์ผ๋ฉด -1 ์ถ๋ ฅ | ||
if (list.isEmpty()) { | ||
out.println(-1); | ||
return; | ||
} | ||
|
||
// ์์ผ๋ฉด ์์๋๋ก ์ถ๋ ฅ | ||
list.forEach(out::println); | ||
} | ||
} |