Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define hell 1000000007
#define hell2 998244353
#define lcm(a, b) (a * b) / __gcd(a, b)
#define ll long long
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define pb push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define ret(x) return cout << x, 0;
#define endl '\\n'

const ll MAX = 1000005;
const ll SQN = 330;
const ll LG = 31;
const double PI = atan(1) * 4;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll k;
  cin >> k;
  ll rem = 0;
  rep(i, 1, MAX) {
    ll r = (10 * rem + 7) % k;
    if (r == 0)
      ret(i);
    rem = r;
  }
  ret(-1);
}

Error: 3

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define i(a, n) int a = n;
#define l(a, n) ll a = n;
#define d(a, n) double a = n;
#define s(a) string a;
#define c(a)                                                                   \\
  ll a;                                                                        \\
  cin >> a;                                                                    \\
  a
#define cd(a)                                                                  \\
  double a;                                                                    \\
  cin >> a;
#define cs(a)                                                                  \\
  string a;                                                                    \\
  cin >> a;
#define ci(a) cin >> a;
#define co(a) cout << a;
#define cos(a) cout << a << " ";
#define con(a) cout << a << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define nl cout << endl;
#define ca(arr, n)                                                             \\
  for (ll i = 0; i < n; i++)                                                   \\
    cin >> arr[i];
#define f0(i, a, n) for (ll i = a; i >= n; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define f1(i, a, n) for (ll i = a; i < n; i++)
#define T                                                                      \\
  ll t = 1;                                                                    \\
  cin >> t;                                                                    \\
  while (t--)
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;

int main() {
  fast;
  ll k, x = 0;
  cin >> k;
  f(i, 1000005) {
    ll temp = (10 * x + 7) % k;
    if (temp == 0)
      return i;
    x = temp;
  }
  return -1;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/