#include using namespace std; typedef unsigned long long ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; typedef pair pll; #define REP(i,n) for(ll i=0;i> n; vector digit_comb[MAX_DIGIT+1]; REPR(c5,30)REP(c3,30){ if(c5*3+c3>MAX_DIGIT)continue; digit_comb[c5*3+c3].push_back(make_pair((int)c5*3,(int)c3)); } ll beforecnt = 0; ll cnt = 0; ll iter = 0; while(cnt < n){ beforecnt = cnt; ++iter; vector digits = digit_comb[iter]; if(digits.empty())continue; REP(i,digits.size()){ pii c53 = digits[i]; cnt += memo_comb[c53.first+c53.second-1][c53.second]; } } // bit 1 means '5' // bit 0 means '3' ll countdown = n-beforecnt-1; ll now = 0; ll t = -1; while(true){ t += 2; int bc = __builtin_popcount(t); if(bc%3 != 0)continue; if(now!=countdown){ ++now; continue; } ll tmp = t; string res = ""; while(res.size() != iter){ if(tmp%2)res += '5'; else res += '3'; tmp /= 2; } reverse(ALL(res)); cout << res << endl; return 0; } return 0; }