Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created December 6, 2012 13:11
Show Gist options
  • Save juanfal/4224358 to your computer and use it in GitHub Desktop.
Save juanfal/4224358 to your computer and use it in GitHub Desktop.
Solution to the 3rd EulerProj problem
// euler3.cpp
// juanfc 2012-06-24
// 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()
{
typedef long long int Tlli;
Tlli prime = 0;
Tlli a = 600851475143LL; // a long long constant
for (Tlli i = 3; i <= a; i += 2) { // even number are not prime
if (a % i == 0)
// this avoids composite numbers divide what remains
a /= (prime = i);
cout << prime << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment