diff --git a/code_study/Baekjoon/python/10830.py b/code_study/Baekjoon/python/10830.py new file mode 100644 index 0000000..7e94bed --- /dev/null +++ b/code_study/Baekjoon/python/10830.py @@ -0,0 +1,27 @@ +def matrix_multiply(A, B) : + B_T = list(zip(*B)) + + return [[sum(a*b for a,b in zip(row_A, col_B))%1000 for col_B in B_T] for row_A in A] + +def power_matrix(A, B) : + if B == 1 : + return [[n % 1000 for n in row] for row in A] + + half = power_matrix(A, B//2) + result = matrix_multiply(half, half) + + if B%2==1 : + result = matrix_multiply(result, A) + + return result + +def print_matrix(A) : + for row in A : + print(*row) + +N, B = map(int, input().split()) +A = [] +for _ in range(N) : + A.append(list(map(int,input().split()))) + +print_matrix(power_matrix(A, B)) diff --git a/code_study/Baekjoon/python/5717.py b/code_study/Baekjoon/python/5717.py new file mode 100644 index 0000000..14e192d --- /dev/null +++ b/code_study/Baekjoon/python/5717.py @@ -0,0 +1,2 @@ +while (n := list(map(int, input().split()))) != [0,0] : + print(sum(n)) \ No newline at end of file diff --git a/code_study/Baekjoon/ts/13172.ts b/code_study/Baekjoon/ts/13172.ts new file mode 100644 index 0000000..162a3bc --- /dev/null +++ b/code_study/Baekjoon/ts/13172.ts @@ -0,0 +1,25 @@ +export {}; +const input = require("fs").readFileSync(0).toString().trim().split('\n'); +const MOD = BigInt(1000000007); + +const power = (num: bigint, n: bigint): bigint => { + if(n===BigInt(0)) return BigInt(1); + else if(n===BigInt(1)) return num%MOD; + + const half = power(num, n/BigInt(2)); + let result = (half * half) % MOD; + + if(n%BigInt(2) === BigInt(1)) result = (result*num)%MOD; + + return result; +} + +let result = BigInt(0); + +for(let line of input.slice(1)) { + const [N, S] = line.split(" ").map(BigInt); + + result = (result + (S * power(N, MOD - BigInt(2))) % MOD) % MOD; +} + +console.log(result.toString()); \ No newline at end of file