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

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

 

8394๋ฒˆ: ์•…์ˆ˜

์ฒซ์งธ ์ค„์— ํšŒ์˜์— ์ฐธ์„ํ•œ ์‚ฌ๋žŒ์˜ ์ˆ˜ n (1 ≤ n ≤ 10,000,000)์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/8394
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)
	var dp = make([]int, n+1)
	dp[1] = 1
	dp[2] = 2
	for i := 3; i < n+1; i++ {
		dp[i] = (dp[i-1] + dp[i-2]) % 10
	}
	fmt.Fprintln(writer, dp[n])
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    dp = [0, 1, 2]
    for i in range(3, n+1):
        dp.append((dp[i-1] + dp[i-2]) % 10)
    print(dp[n])
728x90
๋Œ“๊ธ€