Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. int main() {
  2. long int calcNum = 600851475143;
  3. long int answer;
  4. int found=0;
  5. for (long int i = (calcNum-2); i>0; i=i-2){
  6. printf("Checking if %li is a factor of %li \n",i,calcNum);
  7. if (calcNum%i==0) { //if a factor
  8. printf("Checking though the factors of %li to check for primes.",i);
  9. for (long int j = 2; j<i; j++) { //check through all possible factors
  10. printf("Currently checking %li.\n", j);
  11. if (i%j==0) { // if factor is found
  12. break; // go back to the i for loop
  13. printf("%li is a factor of %li \n",i,calcNum);
  14. }
  15. if (j==i-1) {
  16. found=1;
  17. answer = i;
  18. break;
  19. }
  20. }
  21. if (found==1) {
  22. break;
  23. }
  24. }
  25. }
  26. printf("The largest prime factor of 600851475143 is %li \n",answer);
  27. printf("**This is really inefficient!**");
  28. return 1;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement