Created
December 6, 2012 13:11
-
-
Save juanfal/4224358 to your computer and use it in GitHub Desktop.
Solution to the 3rd EulerProj problem
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
// 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