Skip to content

Instantly share code, notes, and snippets.

@nknize
Created April 30, 2012 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nknize/2559947 to your computer and use it in GitHub Desktop.
Save nknize/2559947 to your computer and use it in GitHub Desktop.
#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