#include #include #include #include #include #include #include #include #include #include using namespace std; template ostream& operator << (ostream& os, vector vec){ for(int i=0; i> dp(2, vector(15, 0)); dp[0][0] = 1; for(int i=0; i> dp_(2, vector(15, 0)); for(int smaller=0; smaller<2; smaller++) for(int mod_15=0; mod_15<15; mod_15++) if(dp[smaller][mod_15]) for(int d:{3,5}){ if(smaller == 0 && d>(s[i]-'0')) continue; int next_smaller = smaller || d<(s[i]-'0'); int next_mod = (mod_15*10+d)%15; dp_[next_smaller][next_mod] += dp[smaller][mod_15]; } if(i>0) for(int d:{3,5}){ dp_[1][d] += 1; } swap(dp, dp_); } return dp[0][0] + dp[1][0]; } int main(){ long long n; //cin >> n; scanf("%lld", &n); int len = 3; while(1){ string s(len, '5'); if(sfb_cnt(s) >= n){ break; } len++; } //cerr << len << " " << sfb_cnt(string(len, '5')) << endl; auto check = [&](long long bits){ string s(len, '3'); for(int i=0; i>i)&1) s[len-1-i] = '5'; } long long cnt = sfb_cnt(s); //cerr << s << " " << cnt << endl; return cnt >= n; }; long long lb = 0; long long ub = 1LL<1){ long long mid = (lb+ub)/2; bool ok = check(mid); (ok? ub : lb) = mid; } string s(len, '3'); for(int i=0; i>i)&1) s[len-1-i] = '5'; } //cout << s << endl; printf("%s\n", s.c_str()); return 0; }