Euler serisinin dokuzuncu yazısında, Project Euler’in 9. sorusunu çözeceğiz;
Orjinal Soru; A Pythagorean triplet is a set of three natural numbers, a b c For which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52 There exists exactly one Pythagorean triplet for which a + b + c = 1000 Find the product a x b x c
Türkçesi; Pisagor teoremindeki üç doğal sayı a b ve c'dir; a2 + b2 = c2 Örneğin, 32 + 42 = 9 + 16 = 25 = 52 a + b + c'nin 1000 değerine sahip olduğu tek bir Pisagor üçlüsü vardır Bu üçlüyü bulup, a x b x c değerini hesaplayın
Önce siz çözmeyi deneyin, çözemezseniz;
private static int Euler9()
{
int a = 0;
int b = 0;
int c = 0;
int s = 1000;
bool found = false;
for (a = 1; a < s / 3; a++)
{
for (b = a; b < s / 2; b++)
{
c = s - a - b;
if (a * a + b * b == c * c)
{
found = true;
break;
}
}
if (found)
{
break;
}
}
return a * b * c;
}
public static class Program
{
public static void Main(string[] args)
{
var Sonuc = Euler9();
Console.WriteLine("Euler 9 sonuç : " + Sonuc)
Console.ReadLine();
}
}Senior Software Engineer, @Microsoft
Ada ve Ege'nin babası ;)
Makale Adedi: 484