문제 바로가기
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
나의 코드 및 설명
def dfs(a, count, result): #a:곱하려고 하는 숫자 count:곱하는 횟수 result:곱한 값
global ans
if count == m: #m번만큼 곱하면,
ans = result #정답은 현재 저장된 곱한 값
return #리턴
result = result * a
dfs(a, count + 1, result) #다음 곱 수행
for test_case in range(1, 11):
t = int(input())
n, m = map(int, input().split())
ans = 0
dfs(n, 0, 1)
print("#{} {}".format(test_case,ans))
다른 코드 및 설명
def dfs(n,m):
if m == 0:
return 1
else:
return n* dfs(n, m-1)
for test_case in range(1, 11):
t = int(input())
n, m = map(int, input().split())
ans = dfs(n, m)
print("#{} {}".format(test_case,ans))
'SWEA (SW Expert Academy) > D3' 카테고리의 다른 글
[SWEA/D3] 1234 비밀번호 / stack (0) | 2023.05.07 |
---|---|
[SWEA/D3] 1228 암호문1 (0) | 2023.05.07 |
[SWEA/D3] 4615 재미있는 오셀로 게임 (1) | 2023.05.06 |
[SWEA/D3] 13428 숫자 조작 / 백트래킹 (1) | 2023.05.03 |
[SWEA/D3] 1860 진기의 최고급 붕어빵 (0) | 2023.04.28 |