using System; using System.Collections.Generic; using System.Text; namespace Euler14 { //Find the longest sequence using a starting number under one million. //Sequence: //e is odd return 3e +1 //e is even return e/2 //Collatz conjecture: all sequence end at 1 class Program { static long Next(long lInput) { bool bIsOdd = true; if (lInput %2 ==0) bIsOdd = false; if (bIsOdd) return (3 * lInput + 1); else return (lInput / 2); } static void Main(string[] args) { long lcount=0; long lmaxcount=0; for (int i = 1; i <= 1000000 ; ++i) { lcount = CountNumberInSequence(i); if (lcount >= lmaxcount) { lmaxcount = lcount; Console.WriteLine("New max found for input " + i + " :" + lmaxcount); } //Console.WriteLine("Result for input " + i + " :" + lcount); } Console.WriteLine("Process Over"); Console.ReadLine(); } private static long CountNumberInSequence(long input) { long current = input; long lcount = 0; while (current > 1) { lcount++; current = Next(current); } lcount++; return lcount; } } }