fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
  5. int main()
  6. {
  7. IOS;
  8. int t, csno=0;
  9. cin >> t;
  10. ll p, a, b;
  11. while(t--){
  12. cin >> p;
  13. cout << "Case " << ++csno << ": ";
  14. if(p==2)
  15. cout << "1 1\n";
  16. else if( p % 4LL != 1LL)
  17. cout << "Impossible\n";
  18. else{
  19. ll limit = sqrt(p);
  20. for(a=limit; a>=1; --a){
  21. b = p - (a*a);
  22. b = sqrt(b);
  23. if(a*a + b*b == p){
  24. cout << min(a,b)<< " " << max(a,b) << endl;
  25. break;
  26. }
  27. }
  28. }
  29. }
  30. return 0;
  31. }
  32.  
Time limit exceeded #stdin #stdout 5s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty