Problem Link

This code finds the largest prime factor of 600851475143. It repeatedly divides out smaller factors, then prints the largest prime factor found.

#include <cmath>
#include <iostream>
#include <map>
using namespace std;

void solve(void) {
  long long n = 600851475143;
  map<long long, int> ans;
  for (long long i=2; i*i<=n; i++) {
    while (!(n % i)) ans[i]++, n /= i;
  }
  if (n > 1) ans[n]++;

  cout << ans.rbegin()->first;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  solve();
  return 0;
}