ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

14916๋ฒˆ: ๊ฑฐ์Šค๋ฆ„๋ˆ

์ฒซ์งธ ์ค„์— ๊ฑฐ์Šค๋ฆ„๋ˆ ์•ก์ˆ˜ n(1 ≤ n ≤ 100,000)์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/14916
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanln(reader, &n)

	numOfFive, numOfTwo := 0, 0
	var isAvailable bool

	for n >= 0 {
		if n%5 == 0 {
			numOfFive = n / 5
			isAvailable = true
			break
		} else {
			n -= 2
			numOfTwo++
		}
	}

	if isAvailable {
		fmt.Fprintln(writer, numOfFive+numOfTwo)
	} else {
		fmt.Fprintln(writer, -1)
	}
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/14916
import sys

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    num_of_five, num_of_two = 0, 0
    is_available = False

    while n >= 0:
        if n%5 == 0:
            num_of_five = n // 5
            is_available = True
            break
        else:
            n -= 2
            num_of_two += 1
    
    if is_available:
        print(num_of_five + num_of_two)
    else:
        print(-1)
728x90
๋Œ“๊ธ€