====== n제곱 계산 ====== ===== 풀이 ===== * [[ps:problems:boj:12925]]와 동일한 문제. 풀이는 그쪽 참고 ===== 코드 ===== """Solution code for "BOJ 12925. Numbers". - Problem link: https://www.acmicpc.net/problem/12925 - Solution link: http://www.teferi.net/ps/problems/boj/12925 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() * Dependency: [[:ps:teflib:combinatorics#linear_homogeneous_recurrence|teflib.combinatorics.linear_homogeneous_recurrence]] {{tag>BOJ ps:problems:boj:플래티넘_1}}