#include #include using namespace std; long long int fact[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 }; size_t f (size_t x) { if (x == 0) { return 1; } size_t val = 0; while (x > 0) { val += fact[x % 10]; x /= 10; } return val; } int main() { ios_base::sync_with_stdio(false); long long int y; cin >> y; stringstream oss; int factBase = 9; while (y > 0) { while (y < fact[factBase]) { factBase--; } oss << factBase; y -= fact[factBase]; } string outStr = oss.str (); if (outStr == "1") { outStr = "0"; } for (auto it = outStr.rbegin(); it != outStr.rend(); it++) { cout << *it; } cout << endl; return 0; }