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

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

 

9625๋ฒˆ: BABBA

์ƒ๊ทผ์ด๋Š” ๊ธธ์„ ๊ฑท๋‹ค๊ฐ€ ์‹ ๊ธฐํ•œ ๊ธฐ๊ณ„๋ฅผ ๋ฐœ๊ฒฌํ–ˆ๋‹ค. ๊ธฐ๊ณ„๋Š” ๋งค์šฐ ๋งค์šฐ ํฐ ํ™”๋ฉด๊ณผ ๋ฒ„ํŠผ ํ•˜๋‚˜๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ธฐ๊ณ„๋ฅผ ๋ฐœ๊ฒฌํ–ˆ์„ ๋•Œ, ํ™”๋ฉด์—๋Š” A๋งŒ ํ‘œ์‹œ๋˜์–ด์ ธ ์žˆ์—ˆ๋‹ค. ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋‹ˆ ๊ธ€์ž๊ฐ€ B๋กœ ๋ณ€ํ–ˆ

www.acmicpc.net


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

๐ŸŽจ Go

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

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

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

	var k int
	fmt.Fscanln(reader, &k)
	a, b := countAB(k)
	fmt.Fprintf(writer, "%d %d\n", a, b)
}

func countAB(k int) (a, b int) {
	a = 1
	for i := 0; i < k; i++ {
		prevA, prevB := a, b
		a += prevB - prevA
		b += prevA
	}
	return a, b
}

๐ŸŽจ Python3

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

def count_ab(k):
    a, b = 1, 0
    for i in range(k):
        prev_a, prev_b = a, b
        a += (prev_b - prev_a)
        b += prev_a
    return a, b

if __name__ == "__main__":
    k = int(sys.stdin.readline())
    a, b = count_ab(k)
    print("{} {}".format(a, b))
728x90
๋Œ“๊ธ€