fork download
  1. #pragma GCC optimize("O3,unroll-loops")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define fi first
  5. #define se second
  6. #define ll long long
  7. #define ull unsigned ll
  8. #define sz(x) (int)(x).size()
  9. #define all(x) (x).begin(),(x).end()
  10. #define f0(i,n) for(int i=0;i<n;i++)
  11. #define f1(i,n) for(int i=1;i<=n;i++)
  12. #define fz(i,a,n,z) for(int i=a;i<n;i+=z)
  13. #define rep(i,a,n,z) for(int i=a;i>n;i-=z)
  14. #define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  15. #define file(name) freopen(name".inp","r",stdin);freopen(name".out","w",stdout);
  16. const int N = 1e6 + 5;
  17. void Bai1() {
  18. int n;
  19. cin >> n;
  20. ll B[n + 5] = {};
  21. for (ll i = 1; i <= n; ++i) {
  22. cin >> B[i];
  23. }
  24. ll A[n + 5] = {}, T[n + 5] = {};
  25. A[1] = B[1];
  26. cout << A[1] << " ";
  27. T[1] = A[1];
  28. for (ll i = 2; i <= n; ++i) {
  29. A[i] = B[i] * i - T[i - 1];
  30. T[i] = T[i - 1] + A[i];
  31. cout << A[i] << " ";
  32. }
  33. }
  34. int main() {
  35. faster
  36. ll k;
  37. cin >> k;
  38. if (k == 1) {
  39. cout << 5;
  40. return 0;
  41. }
  42. if (k == 2) {
  43. cout << 8;
  44. return 0;
  45. }
  46. ll lt = 2, i = 1;
  47. while (k >= lt) {
  48. k -= lt;
  49. lt *= 2;
  50. ++i;
  51. }
  52. if (k == 0) {
  53. for (int j = 1; j < i; ++j) cout << 8;
  54. return 0;
  55. }
  56. else {
  57. --k; int d = 0;
  58. string s = "";
  59. while (k > 0) {
  60. if (k % 2 == 1) s = '8' + s;
  61. else s = '5' + s;
  62. ++d;
  63. k /= 2;
  64. }
  65. for (int j = 1; j <= i - d; ++j) {
  66. cout << 5;
  67. }
  68. cout << s;
  69. }
  70.  
  71.  
  72. }
  73. /*-----------------------END-----------------------*/
  74.  
  75.  
Success #stdin #stdout 0s 5284KB
stdin
30
stdout
8888