๊ธฐ๋ก๋ฐฉ

BOJ_1193 : ๋ถ„์ˆ˜์ฐพ๊ธฐ ๋ณธ๋ฌธ

CodingTest/Python

BOJ_1193 : ๋ถ„์ˆ˜์ฐพ๊ธฐ

Soom_1n 2022. 10. 19. 22:11

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

1193๋ฒˆ: ๋ถ„์ˆ˜์ฐพ๊ธฐ

์ฒซ์งธ ์ค„์— X(1 ≤ X ≤ 10,000,000)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • ์ง€๊ทธ์žฌ๊ทธ๋กœ ๊ทธ๋ฆฐ ๋ฐฐ์—ด์—์„œ x๋ฒˆ์งธ ์œ„์น˜์˜ ๋ถ„์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
  • ๋Œ€๊ฐ์„ ์œผ๋กœ ๋ผ์ธ์„ ์„ธ์—ˆ์„๋•Œ ์ง,ํ™€์˜ ๋ถ„์ž,๋ถ„๋ชจ ๊ทœ์น™์ด ๋ฐ˜๋Œ€์ด๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

x = int(input())
line = 0
end = 0

while x > end:
    line += 1
    end += line

diff = end - x

if line % 2 != 0:
    u = diff + 1
    d = line - diff
else:
    u = line - diff
    d = diff + 1
print(f'{u}/{d}')

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • line์€ x๊ฐ€ ํ•ด๋‹นํ•˜๋Š” ๋ผ์ธ ๋ฒˆํ˜ธ์ด๋‹ค.
  • end๋Š” x๊ฐ€ ํ•ด๋‹นํ•˜๋Š” ๋ผ์ธ์˜ ๋ ์ธ๋ฑ์Šค์ด๋‹ค. (1๋ถ€ํ„ฐ line๊นŒ์ง€์˜ ํ•ฉ)
  • ์ง์ˆ˜๋ฒˆ์งธ ๋ผ์ธ๊ณผ ํ™€์ˆ˜๋ฒˆ์งธ ๋ผ์ธ์— ๋”ฐ๋ผ ๋ถ„์ž, ๋ถ„๋ชจ ๊ทœ์น™์„ ๋‹ฌ๋ฆฌ ์ ์šฉํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ์›๋ฆฌ๊ฐ€ ์ƒ๊ฐ๋ณด๋‹ค ์ž˜ ๋– ์˜ค๋ฅด์ง€์•Š์•„์„œ ์ดˆ๋ฐ˜ ๊ทœ์น™์„ ๋‹ค๋ฅธ ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ–ˆ๋‹ค.

728x90

'CodingTest > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_2810 : ์ปตํ™€๋”  (0) 2022.11.05
BOJ_4998 : ์ €๊ธˆ  (0) 2022.11.04
BOJ_5622 : ๋‹ค์ด์–ผ  (0) 2022.10.19
BOJ_17358 : ๋ณต๋ถˆ๋ณต์œผ๋กœ ์ง€๊ตฌ ๋ฉธ๋ง  (0) 2022.10.19
BOJ_14696 : ๋”ฑ์ง€๋†€์ด  (0) 2022.10.19