Project Euler 74

Project Euler 74:

Determine the number of factorial chains that contain exactly sixty non-repeating terms.

Solution: Uz malu optimizaciju koda rješenje se dobija u vremenu oko minute.

static void Main(string[] args)
    long counter = 0;
    List<long> series = new List<long>();
    for (int i = 1; i < 1000000; i++)
        long n=i;
        int tempCounter = 1;
        while (true)
            n = Nextterm(n);
            if (series.Contains(n))
        if (tempCounter == 60)
    Console.WriteLine("Press any key to continie...");
static long Nextterm(long n)
    var str = n.ToString();
    long numb=str.Sum(x=>Factorial(long.Parse(x.ToString())));
    return numb;
static long Factorial(long n)
    long fact=1;
    for (int i = 1; i <= n; i++)
        fact *= i;
    return fact;

About Bahrudin Hrnjica

PhD in Mechanical Engineering, Microsoft MVP for Visual Studio and Development Technologies. Likes .NET, Math,Data Science, Evolutionary Algorithms, Machine Learning, Blogging.

Posted on 03/03/2010, in C#, Project Euler and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

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

You are commenting using your 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