[BOJ 2609] ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ 

 

1. ๋ฌธ์ œ : Link

๋ง๊ทธ๋Œ€๋กœ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

 

2. ํ’€์ด

๋‘ ๊ฐ’์„ ์ž‘์€๊ฐ’์œผ๋กœ ๋‚˜๋ˆ„๋ฉด์„œ ๋‚˜๋จธ์ง€๊ฐ€ ๋‘˜ ๋‹ค 0์ด ๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐพ์•„์„œ ๋ฐฐ์—ด์— ๋„ฃ์–ด ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ์ฐพ์•„์ค€๋‹ค.

์ตœ๋Œ€๊ณต๋ฐฐ์ˆ˜๋Š” ํ•ด๋‹น ๊ฐ’์— ๋ชซ์„ ๊ณฑํ•ด์ฃผ๋ฉด ๋

 

3. ์ฝ”๋“œ

์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•์ด๋ผ๋Š” ์‰ฌ์šด ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ ํ…Œ์ŠคํŠธํ•  ๋•Œ ๋– ์˜ค๋ฅด์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—..

a, b = map(int, input().split())

maxx = max(a,b)
minn = min(a,b)

originmax = maxx
originmin = minn

divide = []

for i in range(minn, 1, -1):
    if maxx % i == 0 and minn % i == 0:
        maxx = maxx/i
        minn = minn/i
        divide.append(i)

if originmax == maxx:
    print(1, maxx * minn)
else:
    one = 1
    for d in divide:
        one *= d
    print(one, int(one * maxx * minn))

 

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ