-
-
Save antila/65250c8d60158ba2207b 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(int64_t 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 = 600851475143; | |
int64_t temp = input; | |
int64_t lastTemp = 0; | |
while (temp != lastTemp) { | |
lastTemp = temp; | |
temp = divide_into_largest_factor(temp); | |
} | |
printf("outta input %lld; largest prime is: %lld\n", input, temp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment