code https://ide.codingblocks.com/s/46266
question - https://hack.codingblocks.com/contests/c/587/915
please help
Pythagoras triplet challenge doubt
Hey Sharad, Pythagoras triplet numbers can be larger so they will not be in range of int. Therefore, you should take long long int instead of int.
infact i have changed it , the code is -
#include
#include
using namespace std;
int main()
{
unsigned long long int n,a,b;
cin>>n;
if(n%2==0)
{
a = ((nn)/4)-1;
b = ((nn)/4)+1;
cout<<a<<" β<<b<<endl;
}
else if(n%2!=0)
{
a = ((nn)-1)/2;
b = ((nn)+1)/2;
cout<<a<<β β<<b<<endl;
}
else{
cout<<β-1"<<endl;
}
return 0;
}
but still one test case doesnβt work out of 5
Actually your logic is wrong as you are only printing the pair which sum to n . But you should print the pairs (a,b) such that aa + bb =nn (i.e. Pythogoreous triplet) which i think is easy to implement
Just iterate i from 0 to sqrt(n) :
whenver nn-i*i is integer that means there exits a pythagoean triplet so ,you are supposed to print these pairs
Take a loook on this Pseudo code
https://ide.codingblocks.com/s/46287
thanks a lot , but i did some changes with my previous logic and all the testcases were accepted.