Largest prime factor | Project Euler | Problem #3

URL to the problem page: https://projecteuler.net/problem=3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143?



#include <iostream>
using namespace std;

int main()
{
    long long number = 600851475143, a, i, counter, j;
    for (i = 2; ; i++) {
        a = number / i;
        counter = 0;
        if (number % a == 0) {
            for (j = 2; j <= sqrt(a); j++) {
                if (a % j == 0) {
                    counter++;
                    break;
                }
            }
            if (counter == 0) {
                cout << "Largest prime factor of " << number << " is  =  " << a << endl;
                break;
            }
        }
    }
    return 0;

Comments

My photo
Ercan Tomac
instagram.com/ercantomac