We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public class Solution {
public static void Main(string[] args) {
int t = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < t; i++) {
long n = Convert.ToInt64(Console.ReadLine());
Console.WriteLine(PythagoreanTriplet(n));
}
}
public static long PythagoreanTriplet(long n) {
long result = -1;
for (long k = 2; k <= n / 3; k++) {
long j = ((n * n) - (2 * n * k)) / (2 * (n - k));
long i = n - k - j;
if (k * k + j * j == i * i) {
result = Math.Max(result, k * j * i);
}
}
return result;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #9: Special Pythagorean triplet
You are viewing a single comment's thread. Return to all comments →
C# code :
using System;
public class Solution { public static void Main(string[] args) { int t = Convert.ToInt32(Console.ReadLine());
}