Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     fstream iof{ "input.txt", ios::in };
  8.     unsigned N;
  9.     iof >> N;
  10.     iof.close();
  11.  
  12.     unsigned maxpot = 1, maxbase = sqrt(N);
  13.     for (unsigned M = 2; M <= maxbase; M++)
  14.     {
  15.         unsigned pot = M * M;
  16.         while(pot * M <= N)
  17.             pot *= M;
  18.         if (pot > maxpot)
  19.             maxpot = pot;
  20.         if (pot == N) break;
  21.     }
  22.  
  23.     iof.open("output.txt", ios::out);
  24.     iof << maxpot;
  25.     iof.close();
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement