Skip to content

Instantly share code, notes, and snippets.

@ClearNB
Last active January 3, 2019 12:40
Show Gist options
  • Save ClearNB/ceb70659d120e3295c8ff5bb255901d1 to your computer and use it in GitHub Desktop.
Save ClearNB/ceb70659d120e3295c8ff5bb255901d1 to your computer and use it in GitHub Desktop.
Special Pythagorean triplet (Java 8 ver) Sample by ClearNB
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
try (Scanner in = new Scanner(System.in)) {
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int n = in.nextInt();
int max_value = -1;
for(int a = 1; a <= n / 3; a++) {
int b = (2 * a * n - n * n) / (2 * a - 2 * n);
int c = n - (b + a);
if(a * a + b * b == c * c && a < b && a < c && b < c) {
max_value = a * b * c;
}
}
System.out.println(max_value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment