using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; this.Ans(int.Parse(Reader.ReadLine())); } private void Ans(int target) { int totalCount = 0; string ans = string.Empty; for (int i = 3; i <= 26 && totalCount <= target; i++) { List subTotal = new List(); for (int j = 1; j * 3 <= i; j++) { List list = this.GetListSub(i - (j * 3), j * 3); subTotal.AddRange(list); } if (totalCount + subTotal.Count >= target) { subTotal.Sort(); string tmp = Convert.ToString(subTotal[target - totalCount - 1], 2).PadLeft(i, '0'); tmp = tmp.Replace('0', '3'); tmp = tmp.Replace('1', '5'); Console.WriteLine(tmp); return; } totalCount += subTotal.Count; } } private Dictionary>> dic = new Dictionary>>(); private List GetListSub(int remain3, int remain5) { if (!dic.ContainsKey(remain3)) { dic.Add(remain3, new Dictionary>()); } if (dic[remain3].ContainsKey(remain5)) { return new List(dic[remain3][remain5]); } List ans = new List(); if (remain3 == 0) { ans.Add(Convert.ToInt64( "1".PadLeft(remain5, '1'),2)); } else if (remain5 == 0) { // } else { List ret = this.GetListSub(remain3 - 1, remain5); ret.ForEach(a => ans.Add(a)); ret = this.GetListSub(remain3, remain5 - 1); ret.ForEach(a => ans.Add(Convert.ToInt64("1" + Convert.ToString(a, 2).PadLeft(remain3 + remain5 - 1, '0'),2))); } dic[remain3].Add(remain5, ans); return ans; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 10000000 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }