ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1934
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscanln(reader, &t)
for i := 0; i < t; i++ {
var a, b int
fmt.Fscanln(reader, &a, &b)
fmt.Fprintln(writer, getLCM(a, b))
}
}
// ์ต์ ๊ณต๋ฐฐ์ ๊ตฌํ๊ธฐ (์ ํด๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ ์ด์ฉ)
func getLCM(first, second int) (lcm int) {
return first * second / getGCD(first, second) // ๋ ์์ ๊ณฑ ๋๋๊ธฐ ์ต๋๊ณต์ฝ์
}
// ์ต๋ ๊ณต์ฝ์ ๊ตฌํ๊ธฐ (์ ํด๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ ์ด์ฉ)
func getGCD(first, second int) (gcd int) {
if first < second { // fn์ ํฐ ๊ฐ์ ์ค๊ฒ ํ๊ธฐ
second, first = first, second
}
for second != 0 { // second๊ฐ 0์ด ๋ ๋๊น์ง ๋ฐ๋ณต
first, second = second, first%second
}
return first
}
๐จ Python3
# https://www.acmicpc.net/problem/1934
import sys
def get_gcd(first, second):
if first < second:
second, first = first, second
while second != 0:
first, second = second, first%second
return first
def get_lcm(first, second):
return first*second / get_gcd(first, second)
if __name__ == "__main__":
t = int(sys.stdin.readline())
for i in range(t):
a, b = list(map(int, sys.stdin.readline().split()))
print(int(get_lcm(a, b)))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2644๋ฒ / ์ด์๊ณ์ฐ [Go][Python3] (0) | 2020.12.10 |
---|---|
BOJ / 10867๋ฒ / ์ค๋ณต ๋นผ๊ณ ์ ๋ ฌํ๊ธฐ [Go][Python3] (0) | 2020.12.09 |
BOJ / 7785๋ฒ / ํ์ฌ์ ์๋ ์ฌ๋ [Go][Python3] (0) | 2020.12.07 |
BOJ / 2606๋ฒ / ๋ฐ์ด๋ฌ์ค [Go][Python3] (0) | 2020.12.06 |
BOJ / 1260๋ฒ / DFS์ BFS [Go][Python3] (0) | 2020.12.05 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- Algorithm
- ๋ชฝ๊ณ ๋๋น
- ๋ฐฑ์ค
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถ
- baekjoon
- ์ด๋ถํ์
- ์คํ
- BOJ
- ์๊ฐ๊ต์ฒด
- ํ๋ก์ด๋์์ฌ
- Golang
- java
- ์๋ฐ
- MongoDB
- go
- ํ
- ballet
- ๋งฅ๋ถํ๋ก
- AWS
- BFS
- ํด์๋งต
- Macbook pro 2012 mid 13
- ๋ฐ๋
- python3
- ๋ถํ ์ ๋ณต
- dp
- ์๊ณ ๋ฆฌ์ฆ
- dfs
- ๋ธ๋ฃจํธํฌ์ค
- Total
- Today
- Yesterday