๋งž์™œํ‹€

[python] ๋ฐฑ์ค€ - 1735. ๋ถ„์ˆ˜ ํ•ฉ ๋ณธ๋ฌธ

Algorithm Problem/Python

[python] ๋ฐฑ์ค€ - 1735. ๋ถ„์ˆ˜ ํ•ฉ

deo2kim 2020. 10. 15. 08:26
๋ฐ˜์‘ํ˜•

๐Ÿค”๋ฌธ์ œ ํ•ด๊ฒฐ

  • S2 | ์ˆ˜ํ•™

  • ๋ถ„์ˆ˜๋ฅผ ๋”ํ•ด์ค€๋‹ค. ( ์ด ์ •๋„๋Š” ๋‹ค ์•Œ๊ณ ์žˆ์„ ๊ฒƒ์ด๋‹ค. )
  • ๋ถ„์ž์™€ ๋ถ„๋ชจ์˜ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜(GCD)๋ฅผ ๊ตฌํ•œ๋‹ค. ( math ํ•จ์ˆ˜์— ์žˆ๋Š” ๊ธฐ๋Šฅ )
  • ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ GCD๋กœ ๋‚˜๋ˆ„์–ด์ค€๋‹ค.

 

๐Ÿ’ป์†Œ์Šค ์ฝ”๋“œ

import math

a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())

bunjja = a1 * b2 + a2 * b1
bunmo = b1 * b2

my = math.gcd(bunjja, bunmo)
bunjja //= my
bunmo //= my

print(bunjja, bunmo)
 

 

๐Ÿ“•๋ฌธ์ œ ํ™•์ธ

์ถœ์ฒ˜: BACKJOON ONLINE JUDGE

๋งํฌ: https://www.acmicpc.net/problem/1735

 

1735๋ฒˆ: ๋ถ„์ˆ˜ ํ•ฉ

์ฒซ์งธ ์ค„๊ณผ ๋‘˜์งธ ์ค„์—, ๊ฐ ๋ถ„์ˆ˜์˜ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ๋œปํ•˜๋Š” ๋‘ ๊ฐœ์˜ ์ž์—ฐ์ˆ˜๊ฐ€ ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. ์ž…๋ ฅ๋˜๋Š” ๋„ค ์ž์—ฐ์ˆ˜๋Š” ๋ชจ๋‘ 30,000 ์ดํ•˜์ด๋‹ค.

www.acmicpc.net

 

๋ฐ˜์‘ํ˜•