Project Euler – Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

#include <cstdio>
int main(int argc, char **argv){
	long long num = 600851475143LL;
	int ans = 0;
	for(int div = 3; ; div += 2)
		if(!(num % div)){
			do { num /= div; } while (!(num % div));
			if(num == 1){
				ans = div;
				break;
			}
		}		
		printf("Answer: %d\n", ans);
		return 0;
}

Advertisements

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