20250829 baekjoon
This commit is contained in:
parent
788d997b7a
commit
aa8cf25955
15
code_study/Baekjoon/python/1629.py
Normal file
15
code_study/Baekjoon/python/1629.py
Normal 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())))
|
||||||
20
code_study/Baekjoon/swift/1629.swift
Normal file
20
code_study/Baekjoon/swift/1629.swift
Normal 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)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user