## Friday, November 25, 2016

### Special Pythagorean triplet

A Pythagorean triplet is a set of three natural numbers, , for which,
For example,
Given , Check if there exists any Pythagorean triplet for which
Find maximum possible value of  among all such Pythagorean triplets, If there is no such Pythagorean triplet print .
Input Format
The first line contains an integer  i.e. number of test cases.
The next  lines will contain an integer .
Constraints
Output Format
Print the value corresponding to each test case in separate lines.
Sample Input 0
2
12
4

Sample Output 0
60
-1

Explanation 0
• For , we have a triplet , whose product is .
• For , we don't have any pythagorean triple.

*******************************
PROGRAM
********************************

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
int t;
scanf("%d",&t);
for(int a0 = 0; a0 < t; a0++){
int n,found=0,i,j,k;
long long int max=0,prod=1;
scanf("%d",&n);
for(i=1;i<=n/3;i++)
{
for(j=i+1;j<=n/2;j++)
{
if(i+j>n)
break;
for(k=j+1;k<=n;k++)
{
if(i+j+k>n)
break;
if(i+j+k==n)
{
if(((i*i)+(j*j)==(k*k)))
{
found=1;
prod=i*j*k;
if(prod>max)
max=prod;
}
break;
}
}
}
}
a:
if(found==0)
printf("-1\n");
else
printf("%lld\n",max);
}
return 0;
}