From dab2d539de63f79bb8b7c0194090e4de2bbc96e3 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sun, 2 Nov 2025 18:53:56 +0900 Subject: [PATCH] 20251102 baekjoon --- code_study/Baekjoon/python/13172.py | 25 +++++++++++++++++++ code_study/Baekjoon/python/7287.py | 1 + code_study/Baekjoon/swift/11444.swift | 35 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 code_study/Baekjoon/python/13172.py create mode 100644 code_study/Baekjoon/python/7287.py create mode 100644 code_study/Baekjoon/swift/11444.swift diff --git a/code_study/Baekjoon/python/13172.py b/code_study/Baekjoon/python/13172.py new file mode 100644 index 0000000..349e69f --- /dev/null +++ b/code_study/Baekjoon/python/13172.py @@ -0,0 +1,25 @@ +MOD = 1000000007 + +def power(x,n) : + if n==0 : + return 1 + if n==1 : + return x%MOD + + half = power(x,n//2) + result = (half*half)%MOD + + if n%2==1 : + result = (result*x)%MOD + + return result + +inverse_element_MOD = lambda x: power(x, MOD-2) +expect_value = lambda a, b : (a*inverse_element_MOD(b))%MOD + +result = 0 +for _ in range(int(input())) : + S, N = map(int, input().split()) + result = (result + expect_value(N,S))%MOD + +print(result) \ No newline at end of file diff --git a/code_study/Baekjoon/python/7287.py b/code_study/Baekjoon/python/7287.py new file mode 100644 index 0000000..95d73de --- /dev/null +++ b/code_study/Baekjoon/python/7287.py @@ -0,0 +1 @@ +print('\n'.join((["285", "syc725"]))) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/11444.swift b/code_study/Baekjoon/swift/11444.swift new file mode 100644 index 0000000..d8dee6f --- /dev/null +++ b/code_study/Baekjoon/swift/11444.swift @@ -0,0 +1,35 @@ +let Mod: Int64 = 1000000007 + +func matrix_multiply_2by2(_ A: [[Int64]], _ B: [[Int64]]) -> [[Int64]] { + var result = Array(repeating: Array(repeating: Int64(0), count: 4), count: 4) + + result[0][0] = (A[0][0]*B[0][0] + A[0][1]*B[1][0])%Mod + result[0][1] = (A[0][0]*B[0][1] + A[0][1]*B[1][1])%Mod + result[1][0] = (A[1][0]*B[0][0] + A[1][1]*B[1][0])%Mod + result[1][1] = (A[1][0]*B[0][1] + A[1][1]*B[1][1])%Mod + + return result +} + +func power_matrix_2by2(_ A: [[Int64]], exponetioal n: Int64) -> [[Int64]] { + if n == 0 { + return [[1,0],[0,1]] + } + + if n == 1 { + return A + } + + let half = power_matrix_2by2(A, exponetioal: n/2) + let result = matrix_multiply_2by2(half, half) + + if n%2 == 1 { + return matrix_multiply_2by2(result, A) + } + + return result +} + +if let n = Int64(readLine() ?? "") { + print(power_matrix_2by2([[1,1],[1,0]], exponetioal: n)[1][0]) +}