ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1145
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var numbers = make([]int, 5)
for i := 0; i < 5; i++ {
fmt.Fscanf(reader, "%d ", &numbers[i])
}
var minLCM int = 10000000000
for i := 0; i < 5; i++ {
for j := i + 1; j < 5; j++ {
lcmOfTwo := getLCM(numbers[i], numbers[j])
for k := j + 1; k < 5; k++ {
lcmOfThree := getLCM(lcmOfTwo, numbers[k])
if lcmOfThree < minLCM {
minLCM = lcmOfThree
}
}
}
}
fmt.Fprintln(writer, minLCM)
}
func getGCD(first, second int) (gcd int) {
if first < second {
second, first = first, second
}
for second != 0 {
first, second = second, first%second
}
return first
}
func getLCM(first, second int) (lcm int) {
return first * second / getGCD(first, second)
}
๐จ Python3
# https://www.acmicpc.net/problem/1145
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__":
numbers = list(map(int, sys.stdin.readline().split()))
min_lcm = 10000000000
for i in range(5):
for j in range(i+1, 5):
lcm_of_two = get_lcm(numbers[i], numbers[j])
for k in range(j+1, 5):
lcm_of_three = get_lcm(lcm_of_two, numbers[k])
min_lcm = min(min_lcm, lcm_of_three)
print(int(min_lcm))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 14916๋ฒ / ๊ฑฐ์ค๋ฆ ๋ [Go][Python3] (0) | 2021.01.27 |
---|---|
BOJ / 2422๋ฒ / ํ์ค์ ์ด ์ดํ๋ฆฌ์์ ๊ฐ์ ์์ด์คํฌ๋ฆผ์ ์ฌ๋จน๋๋ฐ [Go][Python3] (0) | 2021.01.26 |
BOJ / 1969๋ฒ / DNA [Go][Python3] (0) | 2021.01.24 |
BOJ / 2503๋ฒ / ์ซ์ ์ผ๊ตฌ [Go][Python3] (0) | 2021.01.23 |
BOJ / 17626๋ฒ / Four Squares [Go][Python3] (0) | 2021.01.21 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ballet
- ํ
- ๋ฐ๋
- ์๋ฐ
- ์๊ฐ๊ต์ฒด
- ๋ธ๋ฃจํธํฌ์ค
- go
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- AWS
- Algorithm
- dp
- ๋ฐฑ์ค
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- baekjoon
- Macbook pro 2012 mid 13
- MongoDB
- ๋งฅ๋ถ
- BOJ
- ์คํ
- ๋ชฝ๊ณ ๋๋น
- python3
- java
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถํ๋ก
- dfs
- Golang
- ๋ถํ ์ ๋ณต
- ํด์๋งต
- ์ด๋ถํ์
- Total
- Today
- Yesterday