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

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

 

2635๋ฒˆ: ์ˆ˜ ์ด์–ด๊ฐ€๊ธฐ

์ฒซ ๋ฒˆ์งธ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด ์ˆ˜๋Š” 30,000 ๋ณด๋‹ค ๊ฐ™๊ฑฐ๋‚˜ ์ž‘์€ ์–‘์˜ ์ •์ˆ˜์ด๋‹ค.

www.acmicpc.net


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

๐ŸŽจ Go

// https://www.acmicpc.net/problem/2635
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 maxCount int
	var answer []int
	for second := 1; second <= n; second++ {
		var numbers = []int{n, second}
		for i := 2; numbers[i-2]-numbers[i-1] >= 0; i++ {
			numbers = append(numbers, numbers[i-2]-numbers[i-1])
		}
		if maxCount < len(numbers) {
			maxCount = len(numbers)
			answer = numbers
		}
	}
	fmt.Fprintln(writer, maxCount)
	for i := 0; i < len(answer); i++ {
		fmt.Fprintf(writer, "%d ", answer[i])
	}
	fmt.Fprintln(writer, "")
}

๐ŸŽจ Python3

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

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    max_count = 0
    answer = []
    for second in range(1, n+1):
        numbers = [n, second]
        i = 2
        while numbers[i-2]-numbers[i-1] >= 0:
            numbers.append(numbers[i-2]-numbers[i-1])
            if max_count < len(numbers):
                max_count = len(numbers)
                answer = numbers
            i += 1
    print(max_count)
    for i in answer:
        print("{} ".format(i), end='')
    print()
728x90
๋Œ“๊ธ€