Skip to content

Instantly share code, notes, and snippets.

@fredrikwarngard
Created February 10, 2015 12:58
Show Gist options
  • Save fredrikwarngard/154143a07addfdb87829 to your computer and use it in GitHub Desktop.
Save fredrikwarngard/154143a07addfdb87829 to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <inttypes.h>
int64_t divide_into_largest_factor(int input) {
int64_t divisor = 2;
if (2 < input) {
while (divisor < (sqrt(input)+1)) {
if (input % divisor == 0) {
return (input / divisor);
} else {
++divisor;
}
}
}
return input;
}
int main() {
(int64_t) input = (int64_t)600851475143;
int64_t temp = input;
int64_t lastTemp = 0;
while (temp != lastTemp) {
lastTemp = temp;
temp = divide_into_largest_factor(temp);
}
printf("outta input %d; largest prime is : %d\n", input, temp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment