The problem states:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Here is my attempt in C++
#include <bits/stdc++.h>
using namespace std;
void ProblemThree(long long int n) {
bool prime[n];
memset(prime, true, sizeof(prime));
for (int i = 2; i * i < n; i++) {
if (prime[i]) {
if (n % i == 0) {
printf("d", i);
for (int k = 2 * i; k <= n; k += i) {
prime[k] = false;
}
}
}
}
}
int main() {
ProblemThree(600851475143);
}
The program unexpectedly crashes, with the compiler showing no errors. Why is that and how can I stop it from happening?