public
Created

ix's C solution for Project Euler #14

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <stdio.h>
 
int main(int argc, char **argv)
{
int longest = 0;
int terms = 0;
int i;
unsigned long j;
 
for (i = 1; i <= 1000000; i++)
{
j = i;
int this_terms = 1;
 
while (j != 1)
{
this_terms++;
 
if (this_terms > terms)
{
terms = this_terms;
longest = i;
}
 
if (j % 2 == 0)
{
j = j / 2;
}
else
{
j = 3 * j + 1;
}
}
}
 
printf("longest: %d (%d)\n", longest, terms);
return 0;
}

This solution was copied from the thread for Project Euler problem #14.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.