fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n = 100;
  8.  
  9. cout << "n: " << n << endl;
  10.  
  11. int h=n>>1;
  12. for(int p=0,pp=0;pp<=h;++p,pp=p*p)
  13. {
  14. int k=sqrt(n-pp);
  15. if(pp+k*k==n) cout<<n<<" = "<<p<<"^2 + "<<k<<"^2"<<endl;
  16. }
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
n: 100
100 = 0^2 + 10^2
100 = 6^2 + 8^2