백준/1000 ~
[백준 / C#] 1463 : 1로 만들기
무오_
2023. 7. 11. 18:34
using System;
class Program
{
static int n = int.Parse(Console.ReadLine());
static int[] result = new int[1000001];
static void Main(string[] args)
{
result[1] = 0;
for(int i=2; i<=n; i++)
{
result[i] = result[i - 1] + 1;
if (i % 2 == 0) result[i] = Math.Min(result[i], result[i / 2] + 1);
if (i % 3 == 0) result[i] = Math.Min(result[i], result[i / 3] + 1);
}
Console.WriteLine(result[n]);
}
}