Problem p02660 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57)
    f ^= c == 45, c = getchar();
  while (c > 47 && c < 58)
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
int main(void) {
  int x = 0;
  LL a = 0, i, p = 1, q = -1, N = IN();
  while (N % 2 == 0) {
    x++;
    N /= 2;
  }
  a += e[x], x = 0;
  while (N % 3 == 0) {
    x++;
    N /= 3;
  }
  a += e[x], x = 0;
  while (N % 5 == 0) {
    x++;
    N /= 5;
  }
  a += e[x];
  while (q * q <= N) {
    p += 6, q += 6;
    x = 0;
    while (!(N % p)) {
      x++;
      N /= p;
    }
    a += e[x];
    x = 0;
    while (!(N % q)) {
      x++;
      N /= q;
    }
    a += e[x];
  }
  if (N > 1)
    a++;
  return printf("%lld\\n", a), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef long long LL;
const int e[40] = {0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5,
                   5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8};
const LL UnUseMethod = 4759123141;
int sz = 0;
LL N, factors[100];
LL IN(void) {
  LL x = 0;
  short f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
LL GCD(LL a, LL b) { return !b ? a : GCD(b, a % b); }
LL BinaryModularPower(LL x, LL y, LL mod) {
  LL p = x, v = 1;
  for (; y; y >>= 1, p = (p * p) % mod) {
    if (y & 1)
      v = (v * p) % mod;
  }
  return v;
}
LL Mult(LL x, LL y, LL mod) {
  LL temp = x * y - (LL)((long double)x / mod * y + 1e-8) * mod;
  return temp < 0 ? temp + mod : temp;
}
int MillerRabin(LL x) {
  if (x == 1 || ((x != 2) && (x % 2 == 0)))
    return 0;
  const int base[8] = {2, 3, 5, 7, 11, 13, 17, 19};
  for (int i = 0; i < 8; i++) {
    if (x == base[i])
      return 1;
    else if (x % base[i] == 0)
      return 0;
  }
  int loop = 0;
  LL y = x - 1, now, keep;
  while (!(y & 1)) {
    y >>= 1;
    loop++;
  }
  for (int i = 0; i < 8; i++) {
    now = BinaryModularPower(base[i], y, x);
    for (int j = 0; j < loop; j++) {
      keep = now, now = Mult(now, now, x);
      if (now == 1 && keep != 1 && keep != x - 1)
        return 0;
    }
    if (now != 1)
      return 0;
  }
  return 1;
}
LL PollardRho(LL n) {
  if (n == 1)
    return n;
  if (n % 2 == 0)
    return 2;
  srand(time(NULL));
  int j = 2;
  LL divisor = 1, x = rand() % (n - 2) + 2, y = x;
  for (int i = 1; divisor == 1; i++) {
    x = (Mult(x, x, n) + rand() % (n - 1) + 1) % n;
    divisor = GCD((x < y) ? y - x : x - y, n);
    if (divisor == n)
      return PollardRho(n);
    if (i == j) {
      y = x, j <<= 1;
    }
  }
  return divisor;
}
void Find(LL n) {
  if (n == 1)
    return;
  if (MillerRabin(n)) {
    factors[sz++] = n;
    return;
  }
  LL p = n;
  while (p == n) {
    p = PollardRho(n);
  }
  Find(p), Find(n / p);
}
int main(void) {
  int count = 0;
  LL a, p = 1, q = -1;
  N = IN();
  if (N == 1)
    return puts("0"), 0;
  while (!(N % 2)) {
    count++;
    N /= 2;
  }
  a = e[count], count = 0;
  while (!(N % 3)) {
    count++;
    N /= 3;
  }
  a += e[count];
  while (q * q <= UnUseMethod) {
    p += 6, q += 6, count = 0;
    while (!(N % p)) {
      count++;
      N /= p;
    }
    a += e[count], count = 0;
    while (!(N % q)) {
      count++;
      N /= q;
    }
    a += e[count];
  }
  if (N <= UnUseMethod) {
    if (N > 1) {
      a++;
    }
    return printf("%lld\\n", a), 0;
  } else
    p = 0;
  Find(N);
  while (p < sz) {
    count = 0;
    while (N % factors[p] == 0) {
      count++;
      N /= factors[p];
    }
    a += e[count];
    p++;
  }
  if (N > 1) {
    a++;
  }
  return printf("%lld\\n", a), 0;
}