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

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

 

1904๋ฒˆ: 01ํƒ€์ผ

์ง€์›์ด์—๊ฒŒ 2์ง„ ์ˆ˜์—ด์„ ๊ฐ€๋ฅด์ณ ์ฃผ๊ธฐ ์œ„ํ•ด, ์ง€์›์ด ์•„๋ฒ„์ง€๋Š” ๊ทธ์—๊ฒŒ ํƒ€์ผ๋“ค์„ ์„ ๋ฌผํ•ด์ฃผ์…จ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด ๊ฐ๊ฐ์˜ ํƒ€์ผ๋“ค์€ 0 ๋˜๋Š” 1์ด ์“ฐ์—ฌ ์žˆ๋Š” ๋‚ฑ์žฅ์˜ ํƒ€์ผ๋“ค์ด๋‹ค. ์–ด๋Š ๋‚  ์ง“๊ถ‚์€ ๋™์ฃผ๊ฐ€ ์ง€์›์ด๏ฟฝ๏ฟฝ

www.acmicpc.net


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

๐ŸŽจ Go

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanln(reader, &n)
	sequence := countBinarySequence(n)
	fmt.Println(sequence[n-1])
}

func countBinarySequence(n int) (sequence []int) {
	sequence = append(sequence, 1, 2)
	for i := 3; i<n+1; i++ {
		sequence = append(sequence, (sequence[i-2]+sequence[i-3])%15746)
	}
	return
}

๐ŸŽจ Python3

import sys

def count_binary_sequence(n):
    sequence = [1, 2]
    for i in range(3, n+1):
        sequence.append((sequence[i-2]+sequence[i-3])%15746)
    return sequence

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    sequence = count_binary_sequence(n)
    print(sequence[n-1])
728x90
๋Œ“๊ธ€