Skip to content

Instantly share code, notes, and snippets.

@siisee11
Created November 10, 2019 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siisee11/8b70a8a4a7116cba513bbedce59df24b to your computer and use it in GitHub Desktop.
Save siisee11/8b70a8a4a7116cba513bbedce59df24b to your computer and use it in GitHub Desktop.
#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