My code fails 2 out of 5 test cases. Can't download test cases. I have used a different approach than the solution. Please help me resolve it

// assumes n,root and n+i as pythagoras triplets where root=sqrt((n+i)^2-n^2) i.e root=sqrt(i*(2*n+ i)). Passes first 3 out 5 test cases
using namespace std;
int main() {
unsigned int n;

int i;
double root;
    root= sqrt(i*(2*n+ i));
    if(!(root-int(root))){  //checks if root is an integer
cout<<root<<" "<<n+i<<endl;
return 0;


Plz send your code by saving on ide so that I can check for error in your code


Your code fails in following types of test cases,
for eg, when n=24,
Expected output : 143 145
Your output : 7 25

It is mention in the question that you have to print pythagoras triplet in increasing order only, so if N=24, you can have a triplet less than 24, rather you have to take triplets greater than it…