Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int max_prime_fac(const long n) {
  6.     long no = n;
  7.     long maxfac = 0;
  8.     if (no % 2 == 0){
  9.         no = no / 2;
  10.     }
  11.     int i = 3;
  12.     while (i*i <= no) {
  13.         if (no%i == 0) {
  14.             no = no / i;
  15.             maxfac = i;
  16.         }
  17.         else {
  18.             i += 2;
  19.         }
  20.     }
  21.     if (no > maxfac) {
  22.         maxfac = no;
  23.     }
  24.     return maxfac;
  25. }
  26.  
  27. int main() {
  28.     cout << max_prime_fac(600851475143) << endl;
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement