Guest User

Untitled

a guest
Jun 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <math.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6. string sub (string x )
  7. {
  8.     int q=0; string y ;double r=0;
  9.     for(int i= x.size()-1  ; i>=0 ; i-- )
  10.     {q+=( x[i]-48) *pow ( 10,r );r++;}
  11.     q--;
  12.     while (q>0)
  13.     {
  14.         y.insert(y.begin() , (q%10) +48);
  15.         q=q/10;
  16.     }
  17.     return y;
  18. }
  19. string add (string x , string y)
  20. {
  21.     int xs=x.size() ,ys=y.size() ;
  22.     for (int b=0 ; b <(xs-ys) ;b++ )
  23.         y.insert(y.begin(), '0');
  24.  
  25.     string  h; int carry=0 ,s=0;
  26.  
  27.     for(int i=(x.size()-1) ;i>=0 ;i--)
  28.     {
  29.  
  30.         int f=x[i]-48 , j=y[i]-48 ;
  31.         s=f+j+carry;
  32.         if (s>9)
  33.         {
  34.             h.insert(h.begin() ,((s-10)+48));
  35.             carry=1;
  36.             if (i==0)
  37.                 h.insert(h.begin() ,((s/10)+48));
  38.  
  39.         }
  40.         else
  41.         {
  42.             h.insert(h.begin() ,(s+48));
  43.             carry=0;
  44.         }
  45.  
  46.     }
  47.     return h;
  48. }
  49. string mul (string x , string y)//هنا بتشتغل، جربي كده
  50. {
  51.     int xm , ym , xs = x.size() , ys = y.size() ,m ;
  52.     string k="";
  53.     for (int i=ys-1 ; i>=0 ; i--)
  54.     {
  55.         string t="";int carry=0;
  56.         for (int f=xs-1 ; f>=0 ; f--)
  57.         {
  58.             xm=x[f]-48; ym =y[i]-48;
  59.             m=(xm*ym)+carry;
  60.             if (m>9)
  61.             {
  62.                 t.insert(t.begin() ,((m%10)+48));
  63.                 carry=m/10;
  64.                 if (f==0)
  65.                     t.insert(t.begin() ,((m/10)+48));
  66.  
  67.             }
  68.             else
  69.             {
  70.                 t.insert(t.begin() ,(m+48));
  71.                 carry=0;
  72.             }
  73.  
  74.         }
  75.         for (int d=ys-1-i ; d>0 ; d-- )
  76.             t.insert(t.end() , '0');
  77.         k=add(t,k);
  78.     }
  79.  
  80.     while( k.size()>1 && k[0]=='0')
  81.         k.erase(0,1);
  82.     return k;
  83. }
  84. int main ()
  85. {
  86.     freopen("myDearInput.in", "r", stdin);
  87.     string x  , sum ; int n;
  88.     vector<string> v;
  89.     for (int i=1 ; i<1001 ; i++)
  90.     {
  91.         sum="1";
  92.         x=1;
  93.         while (x> "1")
  94.         {
  95.             sum =  mul(sum , x) ;
  96.             x = sub(x);
  97.         }
  98.         v.push_back(sum);
  99.     }
  100.     while (cin >> n)
  101.     {
  102.         cout <<n<<"!"<<endl << v[n] <<endl;
  103.     }
  104.     return 0;
  105. }
Add Comment
Please, Sign In to add comment