나의 브을로오그으

[c++] 1463번 : 1로 만들기 본문

알고리즘/BaekJoon

[c++] 1463번 : 1로 만들기

__jhp_+ 2022. 6. 3. 09:07

https://www.acmicpc.net/problem/1463

 

1463번: 1로 만들기

첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다.

www.acmicpc.net

#include <iostream>
using namespace std;

#define MIN(a, b) (a < b ? a : b)

int F(int N)
{
	if (N <= 1) return 0;
	int s1 = F(N / 3) + N % 3 + 1;
	int s2 = F(N / 2) + N % 2 + 1;
	return MIN(s1, s2);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N = 0, min = 0;
	cin >> N;

	min = F(N);
	cout << min << '\n';
	return 0;
}