Created
February 10, 2015 12:58
-
-
Save fredrikwarngard/154143a07addfdb87829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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