Euler Problem 278


Euler Problem 278:

Suština zadatka je da se pronađe najveći broj koji se ne može napisati preko linearne kombinacije brojeva. Najveći broj koji se ne može napisati u obliku linearne kombinacije 3 relativno prosta a,b,c broja da je izrazom:

f(a,b,c)=2abc-ab-ac-bc

Problem sa matematičke olimpijade iz 1983. godine održan u Parizu.

Kada se zna ova činjenica implementacija u C# se može vrlo jednostavno napisati.

var primes = (from p in Enumerable.Range(2, 4998) where IsPrime(p) select (long)p).ToList();
var pr = from p in primes
         from q in primes
         from r in primes
         where p < q && q < r
         select new { p, q, r };
var result = pr.Aggregate(0L, (sum, PQR) => sum += 2*PQR.p * PQR.q * PQR.r -
                                                   PQR.p * PQR.q -
                                                   PQR.p * PQR.r -
                                                   PQR.r * PQR.q);

About Bahrudin Hrnjica

PhD in Mechanical Engineering, Microsoft MVP for .NET. Likes .NET, Math, Mechanical Engineering, Evolutionary Algorithms, Blogging.

Posted on 16/03/2010, in 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:

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