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

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
#define f(var, start, end) for (ll var = start; var < end; ++var)
#define rf(var, start, end) for (ll var = start; var >= end; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(X) X.begin(), X.end()
#define nl cout << "\\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a, b, c)                                                        \\
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \\
       << endl;
#define trace4(a, b, c, d)                                                     \\
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \\
       << #d << ": " << d << endl;
#define OC                                                                     \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout)
#define MOD (ll)1e9 + 7; // change it for other mods
#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
ll cnt = 0;

void prime(ll x) {
  ll ans = 0;
  while (x % 2 == 0) {
    ans++;
    x = x / 2;
  }

  cnt += (-1 + sqrt(1 + 8 * ans)) / 2;

  for (ll i = 3; i * i <= x; i += 2) {
    ans = 0;
    while (x % i == 0) {
      ans++;
      x = x / i;
    }
    cnt += (-1 + sqrt(1 + 8 * ans)) / 2;
  }

  if (x > 2) {
    cnt++;
  }
}

int main() {
  ll n;
  scanf("%lld", &n);
  prime(n);
  printf("%lld\\n", cnt);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
#define f(var, start, end) for (ll var = start; var < end; ++var)
#define rf(var, start, end) for (ll var = start; var >= end; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(X) X.begin(), X.end()
#define nl cout << "\\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a, b, c)                                                        \\
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \\
       << endl;
#define trace4(a, b, c, d)                                                     \\
  cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c  \\
       << #d << ": " << d << endl;
#define OC                                                                     \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout)
#define MOD (ll)1e9 + 7; // change it for other mods
#define FAST_IO                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

ll arr[1000001], cnt = 0;

ll prime(ll x) {
  ll ans = 0;
  while (x % 2 == 0) {
    ans++;
    x = x / 2;
  }

  cnt += (-1 + sqrt(1 + 8 * ans)) / 2;

  for (ll i = 3; i * i <= x; i++) {
    ans = 0;
    while (x % i == 0) {
      ans++;
      x = x / i;
    }
    cnt += (-1 + sqrt(1 + 8 * ans)) / 2;
  }

  if (x > 2) {
    cnt++;
  }
}

int main() {
  ll n;
  scanf("%lld", &n);
  prime(n);
  printf("%lld\\n", cnt);
}