재귀함수를 이용한 거듭제곱 표현
package D3;
import java.util.Scanner;
public class 거듭제곱재귀 {
static int T , N , M , ans;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int tc= 1; tc<=10; tc++) {
T = sc.nextInt(); // 테케 수
N = sc.nextInt();
M = sc.nextInt();
ans = N;
func(0);
}
}
public static void func(int cnt) {
//기저
if(cnt == M) {
System.out.print("#" + T + " " + ans + "\n");
return;
}
//구현부
ans = ans*N;
func(cnt+1);
}
}
'알고리즘 > SwExpert recipe' 카테고리의 다른 글
[SWEA] 원재의 메모리 복구 D3 (0) | 2021.03.01 |
---|---|
[SWEA] 회문 D3 (0) | 2021.03.01 |
[SWEA] 장애물 경주 난이도 [D3] (0) | 2021.02.24 |
[SWEA] 준환이의 운동관리 [D3] (0) | 2021.02.24 |
[SWEA] 백만 장자 프로젝트 [D2] (0) | 2021.02.23 |