Problem p01555 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int llint;
typedef bool izryt;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod = 10007;
const llint big = 1e18;
const llint red = 0xE869120;
const llint pro = 1002001;
const llint eiya = 5498513;
llint solve(llint num) {
  // num?????§??????????????¨??????????????°????¨????
  // num???15????????°+10??????90<=num
  llint ans = 5, i, j, gen = 100, fu;
  ans += 4 * (num / 3 + num / 5);
  for (i = 2; gen % 10 == 0 && gen <= num; gen *= 10) {
    ans += 8 * (i * (gen - gen / 10) / 15);
    i++;
    fu = gen;
  }
  ans += 8 * (i * (num - fu) / 15);
  return ans;
}
int main(void) {
  llint s, bmin = 6, bmax = 3.5e16, gen;
  string out;
  cin >> s;
  if (s > 1000) {
    while (bmax - bmin != 1) {
      gen = (bmax + bmin) / 2;
      if (solve(gen * 15 + 10) < s) {
        bmin = gen;
      } else {
        bmax = gen;
      }
    }
  }
  llint start = bmin - 3, stl = solve(start * 15 + 10), i = 0;
  // cout<<stl<<endl;
  i = start * 15 + 11;
  if (s <= 1000) {
    i = 1;
    start = 1;
    stl = 0;
  }
  for (; stl + out.size() < s + 20; i++) {
    if (i % 15 == 0) {
      out += "FizzBuzz";
    } else if (i % 3 == 0) {
      out += "Fizz";
    } else if (i % 5 == 0) {
      out += "Buzz";
    } else {
      out += to_string(i);
    }
  }
  for (i = 0; i < 20; i++) {
    cout << out[s - 1 + i - stl];
  }
  cout << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int llint;
typedef bool izryt;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod = 10007;
const llint big = 1e18;
const llint red = 0xE869120;
const llint pro = 1002001;
const llint eiya = 5498513;
llint solve(llint num) {
  // num?????§??????????????¨??????????????°????¨????
  // num???15????????°+10??????90<=num
  llint ans = 5, i, j, gen = 100, fu;
  ans += 4 * (num / 3 + num / 5);
  for (i = 2; gen % 10 == 0 && gen <= num; gen *= 10) {
    ans += (8 * i * (gen - gen / 10)) / 15;
    i++;
    fu = gen;
  }
  ans += (8 * i * (num - fu)) / 15;
  return ans;
}
int main(void) {
  llint s, bmin = 6, bmax = 5e15, gen;
  string out;
  cin >> s;
  if (s > 1000) {
    while (bmax - bmin != 1) {
      gen = (bmax + bmin) / 2;
      if (solve(gen * 15 + 10) < s) {
        bmin = gen;
      } else {
        bmax = gen;
      }
    }
  }
  llint start = bmin - 3, stl = solve(start * 15 + 10), i = 0;
  i = start * 15 + 11;
  if (s < 1000) {
    i = 1;
    start = 1;
    stl = 0;
  }
  for (; stl + out.size() < s + 20; i++) {
    if (i % 15 == 0) {
      out += "FizzBuss";
    } else if (i % 3 == 0) {
      out += "Fizz";
    } else if (i % 5 == 0) {
      out += "Buzz";
    } else {
      out += to_string(i);
    }
  }
  for (i = 0; i < 20; i++) {
    cout << out[s - 1 + i - stl];
  }
  cout << endl;
  return 0;
}