#include #include #include #define int ptrdiff_t #define div lldiv #define div_t lldiv_t #define abs(a) ((a)<0?-(a):(a)) #define min(a,b) ((a)<(b)?(a):(b)) int N; int conb(int n, int r) { int p = 1; int q = 0; while (r--) p=p*n--/++q; return p; } int check(int a, int rank) { int t = 0; if (a%2 == 0) return 0; while (rank--) if (a & (1ULL << rank)) t++; return t%3 == 0; } void print(int a, int rank) { while (rank--) if (a & (1ULL << rank)) putchar('5'); else putchar('3'); printf("\n"); } main(void) { scanf("%td\n", &N); int rank = 3; for (rank = 3; ; rank++) { int t = 0; int nfive; for (nfive = 3; nfive <= rank; nfive+=3) t += conb(rank-1, nfive-1); if (t < N) { N-=t; } else { break; } } int a=0; do { if (check(a, rank)) if (--N == 0) break; a++; } while(1); print(a, rank); return 0; }