Author: @somashekhar001
Tester: @somashekhar001
Editorialist: @somashekhar001
DIFFICULTY:
SIMPLE
PREREQUISITES:
Mathematics
PROBLEM:
(a,b,c) is a pythagorean triplet you are given b and b is even and you have to find a and c and output maximum sum of triplet (a+b+c),
EXPLANATION:
Let us consider n as a number.
4 * n^2 = 4 * n^2 ( multiply 4 both side)
= ( n^2 + 1 )^2 - ( n^2 - 1 )^2
( n^2 - 1 )^2 + ( 2 * n )^2 = ( n^2 + 1 )^2
a^2 + b^2 = c^2
a = n^2 - 1
b = 2 * n
c= n^2 + 1
sum=a+b+c;
=n^2 - 1 + b + n^2 + 1
=2*n^2+b (n=b/2)
=(b^2 / 2 )+b
SOLUTIONS:
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long T;
cin>>T;//input T testcases
while(T–)
{
long long b;
cin>>b;//taking input b which is even
cout<<((b*b)/2)+b<<endl;
}
return 0;
}