Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int max_prime_fac(const long n) {
- long no = n;
- long maxfac = 0;
- if (no % 2 == 0){
- no = no / 2;
- }
- int i = 3;
- while (i*i <= no) {
- if (no%i == 0) {
- no = no / i;
- maxfac = i;
- }
- else {
- i += 2;
- }
- }
- if (no > maxfac) {
- maxfac = no;
- }
- return maxfac;
- }
- int main() {
- cout << max_prime_fac(600851475143) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement