using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.Target = inpt[1]; decimal[] items = new decimal[inpt[0]]; for (int i = 1; i <= inpt[0]; i++) { items[i - 1] = i; } string ans = "Impossible"; if(CanCreate(items)) { ans = "Possible"; } Console.WriteLine(ans); } private Dictionary dic = new Dictionary(); private decimal Target = 0; private bool CanCreate(decimal[] items) { string key = string.Join("#", items); if(items.Length == 1) { return items[0] == Target; } if(dic.ContainsKey(key)) { return dic[key]; } bool ans = false; for (int i = 0; i < items.Length-1; i++) { for (int j = i + 1; j < items.Length; j++) { List subItems = new List(); subItems.AddRange(items); subItems.RemoveAt(j); subItems.RemoveAt(i); List newItems = new List(); newItems.Add(items[i]+items[j]); newItems.Add(items[i]-items[j]); newItems.Add(items[j]-items[i]); newItems.Add(items[i]*items[j]); if(items[i]!=0) { newItems.Add(items[j] / items[i]); } if(items[j]!=0) { newItems.Add(items[i] / items[j]); } foreach(decimal addItem in newItems) { List tmp = new List(); tmp.AddRange(subItems); tmp.Add(addItem); if(CanCreate(tmp.OrderBy(a=>a).ToArray())) { ans = true; break; } } if(ans) { break; } } if(ans) { break; } } dic[key] = ans; return ans; } 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 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }