Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <cmath>
#include <stdio.h>
int findCase(int n, int nPlus);
// 전역 변수를 정의할 경우 함수 내에 초기화 코드를 꼭 작성해주세요.
int solution(int n) {
int answer = 0;
return findCase(n - 2, 2);
}
int findCase(int n, int nPlus) {
int result = 0;
if (n < 1 || 2*log(n)/log(3) < nPlus) {
return 0;
} else if ( n == 3 && nPlus == 2){
return 1;
} else if ( n == 3 && nPlus == 3) {
return 0;
}
if (n % 3 == 0 && nPlus >= 2){
result += findCase(n / 3, nPlus - 2);
}
result += findCase(n - 1, nPlus + 1);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment