Project Euler Problem 14


The link to the problem can be found here.

http://projecteuler.net/problem=14

#include “stdio.h”
int main()
{
long long int n,num,m;
int terms = 1, max_terms = 1;

for ( m = 13; m 1)
{
if ( n % 2 == 0 )
n = n/2;
else
n = 3*n + 1;
terms++;
}
if ( terms > max_terms)
{
max_terms = terms;
num = m;
}
terms = 1;
}
printf(“The number with largest terms is %lld.\n”,num);
}

This is a brute forced solution. Although there are more elegant methods, I chose this one because of its simplicity.

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