fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, a, b, cnt;
  7. while(cin >> n) {
  8. cnt = 0;
  9. for(int a=1; a < n; a++) {
  10. b = nearbyint(log(n)/log(a));
  11. if ((int)nearbyint(pow(a, b)) == n) {
  12. cout << n << " = " << a << " ^ " << b << endl;
  13. cnt++;
  14. }
  15. }
  16. if (cnt == 0) {
  17. cout << "For " << n << " there are no powers\n";
  18. }
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 4388KB
stdin
1528
6561
125
stdout
For 1528 there are no powers
6561 = 3 ^ 8
6561 = 9 ^ 4
6561 = 81 ^ 2
125 = 5 ^ 3