Pythagors triplet

can you give me the algorihtm how to solve this problem. i am not getting the idea how to solve it.

Hi @ankita_10,
there is a direct formula to find pythagors triplet, which is
if(n<3){
cout<<"-1";
}
else if(!(n&1)){
long long a=n;
long long b=(n/2)(n/2)-1;
long long c=(n/2)
(n/2)+1;
}
else{
long long a=2*((n+1)/2)((n-1)/2);
long long b=((n+1)/2)
((n+1)/2)+((n-1)/2)((n-1)/2);
long long c=((n+1)/2)
((n+1)/2)-((n-1)/2)*((n-1)/2);
}
pls refer to dis.
If u still hv any doubt, feel free to post them here.

errors are coming. the code is :- #include<bits/stdc++.h> using namespace std; int main() { long long int n = 3; cin>>n; if(n<3){ cout<<"-1"; } else if(!(n&1)){ long long a=n; long long b=(n/2)(n/2)-1; long long c=(n/2)(n/2)+1; } else{ long long a=2*((n+1)/2)((n-1)/2); long long b=((n+1)/2)((n+1)/2)+((n-1)/2)((n-1)/2); long long c=((n+1)/2)((n+1)/2)-((n-1)/2)((n-1)/2); } cout<<a<<b<<c<<" "; return 0; } THE ERRORS ARE :- Compiling failed with exitcode 1, compiler output: prog.cpp: In function β€˜int main()’: prog.cpp:11:22: error: expression cannot be used as a function long long b=(n/2)(n/2)-1; ^ prog.cpp:12:22: error: expression cannot be used as a function long long c=(n/2)(n/2)+1; ^ prog.cpp:10:11: warning: unused variable β€˜a’ [-Wunused-variable] long long a=n; ^ prog.cpp:11:11: warning: unused variable β€˜b’ [-Wunused-variable] long long b=(n/2)(n/2)-1; ^ prog.cpp:12:11: warning: unused variable β€˜c’ [-Wunused-variable] long long c=(n/2)(n/2)+1; ^ prog.cpp:15:32: error: expression cannot be used as a function long long a=2((n+1)/2)((n-1)/2); ^ prog.cpp:16:30: error: expression cannot be used as a function long long b=((n+1)/2)((n+1)/2)+((n-1)/2)((n-1)/2); ^ prog.cpp:16:49: error: expression cannot be used as a function long long b=((n+1)/2)((n+1)/2)+((n-1)/2)((n-1)/2); ^ prog.cpp:17:30: error: expression cannot be used as a function long long c=((n+1)/2)((n+1)/2)-((n-1)/2)((n-1)/2); ^ prog.cpp:15:11: warning: unused variable β€˜a’ [-Wunused-variable] long long a=2((n+1)/2)((n-1)/2); ^ prog.cpp:16:11: warning: unused variable β€˜b’ [-Wunused-variable] long long b=((n+1)/2)((n+1)/2)+((n-1)/2)((n-1)/2); ^ prog.cpp:17:11: warning: unused variable β€˜c’ [-Wunused-variable] long long c=((n+1)/2)((n+1)/2)-((n-1)/2)*((n-1)/2); ^ prog.cpp:19:7: error: β€˜a’ was not declared in this scope cout<<a<<b<<c<<" β€œ; ^ prog.cpp:19:10: error: β€˜b’ was not declared in this scope cout<<a<<b<<c<<” β€œ; ^ prog.cpp:19:13: error: β€˜c’ was not declared in this scope cout<<a<<b<<c<<” "; ^

@ankita_10
pls share ur code using ide.codingblocks.com

Hi @ankita_10
pls refer to dis.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.