diff --git a/code_study/Baekjoon/python/1629.py b/code_study/Baekjoon/python/1629.py new file mode 100644 index 0000000..fe785f1 --- /dev/null +++ b/code_study/Baekjoon/python/1629.py @@ -0,0 +1,15 @@ +def solv(a, b, c) : + if b == 1 : + return a%c + + temp = solv(a,b//2,c) + + if b%2 == 1 : + return (temp*temp*a)%c + else : + return (temp*temp)%c + +print(solv(*map(int,input().split()))) + +# 한줄 코드 및 내장함수 사용 코드 +# print(pow(*map(int,input().split()))) \ No newline at end of file diff --git a/code_study/Baekjoon/swift/1629.swift b/code_study/Baekjoon/swift/1629.swift new file mode 100644 index 0000000..1f48809 --- /dev/null +++ b/code_study/Baekjoon/swift/1629.swift @@ -0,0 +1,20 @@ +func solv(_ a:Int, _ b: Int, _ c: Int) -> Int { + if b==1 { + return a%c + } + + let temp:Int = solv(a,b/2,c) + let val:Int = (temp*temp)%c + + if b%2==0 { + return val + } + else { + return (val*(a%c))%c + } +} + +if let input = readLine(), let n = input.split(separator: " ").compactMap({Int($0)}) as? [Int], n.count==3 { + let result = solv(n[0],n[1],n[2]) + print(result) +} \ No newline at end of file