Advertisement
Guest User

potenza

a guest
Jul 31st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. int my_pow(int a, int b)
  6. {
  7.     int i = 0;
  8.     int c = a;
  9.     while(i<b)
  10.     {
  11.         c*=a;
  12.         i++;
  13.     }
  14.     return c;
  15. }
  16.  
  17. int alloca(int N)
  18. {
  19.     std::vector<int> P;
  20.     for(int i=1; i<N; i++)
  21.     {
  22.         for(int j=1; j<N; j++)
  23.         {
  24.             int a = my_pow(i,j);
  25.             if(a<=N) P.push_back(a);
  26.         }
  27.     }
  28.     return *std::max_element(P.begin(),P.end());
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34.     FILE *fr, *fw;
  35.     int N;
  36.  
  37.     fr = fopen("input.txt", "r");
  38.     fw = fopen("output.txt", "w");
  39.  
  40.     fscanf(fr, "%d", &N);
  41.     fprintf(fw, "%d\n", alloca(N));
  42.  
  43.     fclose(fr);
  44.     fclose(fw);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement