Advertisement
juanjo12x

UVA_11565_Simple_Equations

Aug 10th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define LL unsigned long long
  17. using namespace std;
  18.  
  19. int main() {
  20.     int t,A,B,C;
  21.   scanf("%d",&t);
  22.   while(t--){
  23.     scanf("%d %d %d",&A,&B,&C);
  24.     bool sol=false; int x,y,z;
  25.     for(x=-22;x<=22 && !sol ;x++) if(x*x<=C)
  26.      for(y=-100 ; y<=100 && !sol; y++) if(y!=x && x*x + y*y<=C)
  27.       for(z=-100;z<=100 && !sol;z++)
  28.        if(z!=x && z!=y && x+y+z==A && x*y*z==B && x*x + y*y + z*z ==C){
  29.         printf("%d %d %d\n",x,y,z);
  30.         sol=true;
  31.        }
  32.     if (!sol) printf("No solution.\n");  
  33.   }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement