Created
April 30, 2012 16:46
-
-
Save nknize/2559947 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 <iostream> | |
#include <math.h> | |
using namespace std; | |
long long int maximum(long long int a, long long int b) { | |
long long int max = (a > b) ? a : b; | |
return max; | |
} | |
long long int lpf(long long int input) { | |
for(long long int i=sqrt(input); i>=2; i--) { | |
if(input%i==0) return maximum(lpf(i), lpf(input/i)); | |
} | |
return input; | |
} | |
int main(int argc, char* argv) { | |
long input = 600851475143; | |
cout << lpf(input) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment