You are viewing a single comment's thread. Return to all comments →
Java: Both maths ho gya dosto
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int triplet(int n){ int prod = -1; for(int a=1; a<=n/3; a++){ int diff = (a*a)/(n-a); int c = ((n-a)+diff)/2; int b = (n-a)-c; if((a*a)+(b*b) == c*c){ if(a<b && b<c){ prod = Math.max(prod, a*b*c); } } } return prod; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); System.out.println(triplet(n)); } } }
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 →
Java: Both maths ho gya dosto