fork download
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. const auto x = 13;
  8. auto a = 0.0;
  9. auto b = 1;
  10.  
  11. if(x == 1) {
  12. a = 2.0;
  13. b = 0;
  14. } else {
  15. while((a = pow(x, 1.0 / ++b)) > 2.0) {
  16. double dummy;
  17.  
  18. if(modf(a, &dummy) == 0.0) {
  19. break;
  20. }
  21. }
  22. }
  23.  
  24. if(a >= 2.0) {
  25. cout << a << '^' << b << " = " << x << endl;
  26. } else {
  27. cout << "No such a and b exist\n";
  28. }
  29. }
Success #stdin #stdout 0s 4460KB
stdin
Standard input is empty
stdout
No such a and b exist