lucacodorean

Untitled

Feb 12th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. vector<int>x;
  7.  
  8. vector<int> times (vector<int> x, int y);
  9. vector<int> factorial (int n);
  10. vector<int> pow(int n);
  11. void write(vector<int> x);
  12.  
  13. int main()
  14. {
  15.     int a;
  16.     cin>>a;
  17.     pow(a);
  18.     write(x);
  19.     return 0;
  20. }
  21.  
  22. void write(vector<int> x)
  23. {
  24.     reverse(x.begin(), x.end());
  25.     if (x.size()==0)
  26.     {
  27.         cout<<"gol"<<endl;
  28.     }
  29.     else
  30.     {
  31.         for(auto const it : x)
  32.         {
  33.             cout<<it;
  34.         }
  35.     }
  36. }
  37.  
  38. vector<int> times (vector<int> a, int y)
  39. {
  40.     vector<int> aux;
  41.     int t=0;
  42.     for(int i=0; i<a.size(); i++)
  43.     {
  44.         t=t+x[i]*y;
  45.         aux.push_back(t%10);
  46.         t/=10;
  47.     }
  48.     while (t>0)
  49.     {
  50.         aux.push_back(t%10);
  51.         t/=10;
  52.     }
  53.     return aux;
  54. }
  55.  
  56. vector<int> factorial (int n, vector<int> &aux)
  57. {
  58.     aux.push_back(1);
  59.     for(int i=1; i<=n; i++)
  60.     {
  61.         aux=times(x,i);
  62.     }
  63.     return aux;
  64. }
  65.  
  66. vector<int> pow(int n)
  67. {
  68.     factorial(n,x);
  69.     for(int i=1; i<=n; i++)
  70.     {
  71.         x=times(x,n);
  72.     }
  73.     return x;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment