using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { this.MustLength = int.Parse(Reader.ReadLine()); int[] tmp = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CopyCost = tmp[0]; this.PasteCost = tmp[1]; this.MinCost = CopyCost; this.MinCost += (MustLength - 1) * this.PasteCost; long ans = GetAns(1, 1, CopyCost); if(ans< 0) { ans = MinCost; } Console.WriteLine(ans); } private Dictionary> dic = new Dictionary>(); private long GetAns(int copyLength, int reportLength, long subtotal) { if (subtotal > MinCost) { return -1; } if(reportLength >= MustLength) { this.MinCost = Math.Min(MinCost, subtotal); return subtotal; } if(!dic.ContainsKey(copyLength)) { dic.Add(copyLength, new Dictionary()); } if(dic[copyLength].ContainsKey(reportLength)) { return dic[copyLength][reportLength]; } long ans = ((MustLength - reportLength) / copyLength)*PasteCost + subtotal; if((MustLength-reportLength)%copyLength>0) { ans += PasteCost; } long ret = GetAns(copyLength + reportLength, copyLength + reportLength, subtotal + CopyCost + PasteCost); if(ret >= 0) { ans = Math.Min(ans, ret); } ret = GetAns(copyLength, reportLength + copyLength, subtotal + PasteCost); if (ret >= 0) { ans = Math.Min(ans, ret); } if(ans > this.MinCost) { ans = -1; } else { MinCost = ans; } dic[copyLength][reportLength] = ans; return ans; } private long MinCost = 0; private int MustLength; private int CopyCost; private int PasteCost; public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 10 1 3 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }