Project Euler: Problem # 3 solution in C++

/** (From:http://projecteuler.net/index.php?section=problems&id=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 factorOf  = (600851475143);
int num = 2;

while ((num * num) <= factorOf)

if (factorOf % num == 0)
{
cout << num << endl;
factorOf /= num;
}else
num++;

cout << “factor of 600851475143 is: ” << factorOf << endl;
}

Advertisements

About Khuram Ali

Programming... Programming and Programming...!!!

Posted on March 25, 2013, in Algorithms, C++, Programming, Project Euler and tagged . Bookmark the permalink. 3 Comments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: