목차

Numbers (Small)

ps
링크acmicpc.net/…
출처BOJ
문제 번호12727
문제명Numbers (Small)
레벨골드 3
분류

수학

시간복잡도O(Tlogn)
인풋사이즈T<=100, n<=30
사용한 언어Python
제출기록30860KB / 72ms
최고기록56ms
해결날짜2022/01/30

풀이

코드

"""Solution code for "BOJ 12727. Numbers (Small)".

- Problem link: https://www.acmicpc.net/problem/12727
- Solution link: http://www.teferi.net/ps/problems/boj/12727

Tags: [Math]
"""

from teflib import combinatorics

MOD = 1000
COEF = [6, -4]  # A(n)=6A(n-1)-4A(n-2)  ( A(n) = (3+sqrt(5))^n + (3-sqrt(5))^n )
SEED = [2, 6]  # A(0)=2, A(1)=6


def main():
    T = int(input())
    for i in range(T):
        n = int(input())

        answer = combinatorics.linear_homogeneous_recurrence(
            COEF, SEED, n, MOD) - 1
        print(f'Case #{i + 1}: {answer:>03}')


if __name__ == '__main__':
    main()