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

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 __int128
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0)
    val += mod;
  if (val >= mod)
    val -= mod;
  return val;
}
ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2)
      val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
} // namespace

ll const maxn = 3e5 + 5;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unordered_set<ll> st;
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    ll d = i;
    int128 kek = 1;
    bool f = false;
    while (kek <= n) {
      ll lol = n - kek;
      int128 neww = kek * d;
      if (lol % neww == 0) {
        f = true;
        break;
      } else {
        kek = neww;
      }
    }
    if (f)
      st.insert(d);
    if (n / i == i)
      continue;
    ll dd = n / i;
    kek = 1;
    f = false;
    while (kek <= n) {
      ll lol = n - kek;
      int128 neww = kek * dd;
      if (lol % neww == 0) {
        f = true;
        break;
      } else {
        kek = neww;
      }
    }
    if (f)
      st.insert(dd);
  }
  st.insert(n);
  n--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    ll d = i;
    st.insert(d);
    ll dd = n / i;
    if (dd == d)
      continue;
    st.insert(dd);
  }
  st.insert(n);

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << st.size() << endl;

  return 0;
}

/*


*/

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
ll mul(ll a, ll b) {
  ll val = a * b - (ll)((ld)a * b / mod) * mod;
  if (val < 0)
    val += mod;
  if (val >= mod)
    val -= mod;
  return val;
}
ll poww(ll a, ll b) {
  ll val = 1;
  a %= mod;
  while (b > 0) {
    if (b % 2)
      val = mul(a, val);
    a = mul(a, a);
    b >>= 1;
  }
  return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
} // namespace

ll const maxn = 3e5 + 5;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unordered_set<ll> st;
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    ll d = i;
    ll kek = 1;
    bool f = false;
    while (kek <= n) {
      ll lol = n - kek;
      ll neww = kek * d;
      if (lol % neww == 0) {
        f = true;
        break;
      } else {
        kek = neww;
      }
    }
    if (f)
      st.insert(d);
    if (n / i == i)
      continue;
    ll dd = n / i;
    kek = 1;
    f = false;
    while (kek <= n) {
      ll lol = n - kek;
      ll neww = kek * dd;
      if (lol % neww == 0) {
        f = true;
        break;
      } else {
        kek = neww;
      }
    }
    if (f)
      st.insert(dd);
  }
  st.insert(n);
  n--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i)
      continue;
    ll d = i;
    st.insert(d);
    ll dd = n / i;
    if (dd == d)
      continue;
    st.insert(dd);
  }
  st.insert(n);

  cout << st.size() << endl;

  return 0;
}

/*


*/