20250829 baekjoon

This commit is contained in:
songyc macbook 2025-08-29 21:16:21 +09:00
parent 788d997b7a
commit aa8cf25955
2 changed files with 35 additions and 0 deletions

View File

@ -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())))

View File

@ -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)
}