Last active
January 3, 2019 12:40
-
-
Save ClearNB/ceb70659d120e3295c8ff5bb255901d1 to your computer and use it in GitHub Desktop.
Special Pythagorean triplet (Java 8 ver) Sample by ClearNB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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