can you give me the algorihtm how to solve this problem. i am not getting the idea how to solve it.
Pythagors triplet
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<<β "; ^
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.