ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2004
// nCm์ ๋์ 0์ด ์ผ๋ง๋ ๋ง์ด ์ค๋์ง ๊ตฌํ๋ ๋ฌธ์
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, m, count, twoCount, fiveCount int
fmt.Fscanln(reader, &n, &m)
twoCount = getTwoCount(n) - getTwoCount(n-m) - getTwoCount(m)
fiveCount = getFiveCount(n) - getFiveCount(n-m) - getFiveCount(m)
if twoCount > fiveCount {
count = fiveCount
} else {
count = twoCount
}
fmt.Fprintln(writer, count)
}
func getTwoCount(num int) (twoCount int) {
for i := 2; i <= num; i *= 2 {
twoCount += num / i
}
return twoCount
}
func getFiveCount(num int) (fiveCount int) {
for i := 5; i <= num; i *= 5 {
fiveCount += num / i
}
return fiveCount
}
/* ์๊ฐ์ด๊ณผ..
// reader := bufio.NewReader(os.Stdin)
// writer := bufio.NewWriter(os.Stdout)
// defer writer.Flush()
// var n, m, count, twoCount, fiveCount int
// fmt.Fscanln(reader, &n, &m)
// for i := n - m + 1; i <= n; i++ {
// var temp = i
// for temp%2 == 0 && temp > 0 {
// twoCount++
// temp /= 2
// }
// temp = i
// for temp%5 == 0 && temp > 0 {
// fiveCount++
// temp /= 5
// }
// }
// for i := 1; i <= m; i++ {
// var temp = i
// for temp%2 == 0 && temp > 0 {
// twoCount--
// temp /= 2
// }
// temp = i
// for temp%5 == 0 && temp > 0 {
// fiveCount--
// temp /= 5
// }
// }
// if twoCount > fiveCount {
// count = fiveCount
// } else {
// count = twoCount
// }
// fmt.Fprintln(writer, count)
*/
๐จ Python3
# https://www.acmicpc.net/problem/2004
# nCm์ ๋์ 0์ด ์ผ๋ง๋ ๋ง์ด ์ค๋์ง ๊ตฌํ๋ ๋ฌธ์
import sys
def get_two_count(n):
i = 2
two_count = 0
while i <= n:
two_count += n//i
i*=2
return two_count
def get_five_count(n):
i = 5
five_count = 0
while i <= n:
five_count += n//i
i*=5
return five_count
if __name__ == "__main__":
n, m = list(map(int, sys.stdin.readline().split()))
two_count = get_two_count(n) - get_two_count(n-m) - get_two_count(m)
five_count = get_five_count(n) - get_five_count(n-m) - get_five_count(m)
print(min(two_count, five_count))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 4949๋ฒ / ๊ท ํ์กํ ์ธ์ [Go][Python3] (0) | 2020.11.07 |
---|---|
BOJ / 9012๋ฒ / ๊ดํธ [Go][Python3] (0) | 2020.11.06 |
BOJ / 1676๋ฒ / ํฉํ ๋ฆฌ์ผ 0์ ๊ฐ์ [Go][Python3] (0) | 2020.11.04 |
BOJ / 1932๋ฒ / ์ ์ ์ผ๊ฐํ [Python3] (0) | 2020.11.03 |
BOJ / 1149๋ฒ / RGB๊ฑฐ๋ฆฌ [Go] [Python3] (0) | 2020.08.04 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- baekjoon
- ํ๋ก์ด๋์์ฌ
- dp
- Algorithm
- Macbook pro 2012 mid 13
- MongoDB
- ๋งฅ๋ถ
- ์๋ฐ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ฐฑ์ค
- ๋ฐ๋
- ๋ธ๋ฃจํธํฌ์ค
- ๋งฅ๋ถํ๋ก
- python3
- ๋ถํ ์ ๋ณต
- java
- ๋ชฝ๊ณ ๋๋น
- ํด์๋งต
- BFS
- ์ด๋ถํ์
- ballet
- ์๊ณ ๋ฆฌ์ฆ
- Golang
- BOJ
- AWS
- go
- dfs
- ์คํ
- ํ
- ์๊ฐ๊ต์ฒด
- Total
- Today
- Yesterday