Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- long int calcNum = 600851475143;
- long int answer;
- int found=0;
- for (long int i = (calcNum-2); i>0; i=i-2){
- printf("Checking if %li is a factor of %li \n",i,calcNum);
- if (calcNum%i==0) { //if a factor
- printf("Checking though the factors of %li to check for primes.",i);
- for (long int j = 2; j<i; j++) { //check through all possible factors
- printf("Currently checking %li.\n", j);
- if (i%j==0) { // if factor is found
- break; // go back to the i for loop
- printf("%li is a factor of %li \n",i,calcNum);
- }
- if (j==i-1) {
- found=1;
- answer = i;
- break;
- }
- }
- if (found==1) {
- break;
- }
- }
- }
- printf("The largest prime factor of 600851475143 is %li \n",answer);
- printf("**This is really inefficient!**");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement