Finding prime divisors with wheel factorization
Work with larger integers than what int allows

Here, you seem to be asking for templates, so that your code works with any integer (and actually, any type which properly acts like an integer). I will convert the checkdivisor function for you so that you can analyze it, then templating the rest of the code will be left as an exercice:

template&lt;typename Integer&gt;
Integer checkdivisor(Integer n, Integer p) {
  while (n % p == 0) {
    std::cout &lt;&lt; p &lt;&lt; std::endl;
    n /= p;
  }
  return n;
}


Actually, it should even work with any type for which the operations %, / and == have the desired semantics.

Catch errors arising from command-line arguments that cannot be parsed as ints

That one is easy if you look at the documentation of std::stoi: it says that std::stoi throws an std::invalid_argument exception if the string does not represent an integer and an std::out_of_range exception if the string to parse represents an integer too big for the type to hold. Knowing that, you can set up a simple try/catch to handle the errors:

int main(int argc, char* argv[]) {
  for (int i = 1; i &lt; argc; i++) {
    try {
      primedivisors(std::stoi(argv[i]));
    }
    catch (const std::invalid_argument&amp; err) {
      std::cerr &lt;&lt; "the input is not an integer\n";
    }
    catch (const std::out_of_range&amp; err) {
      std::cerr &lt;&lt; "the input is too big\n";
    }
  }
}