Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- string sub (string x )
- {
- int q=0; string y ;double r=0;
- for(int i= x.size()-1 ; i>=0 ; i-- )
- {q+=( x[i]-48) *pow ( 10,r );r++;}
- q--;
- while (q>0)
- {
- y.insert(y.begin() , (q%10) +48);
- q=q/10;
- }
- return y;
- }
- string add (string x , string y)
- {
- int xs=x.size() ,ys=y.size() ;
- for (int b=0 ; b <(xs-ys) ;b++ )
- y.insert(y.begin(), '0');
- string h; int carry=0 ,s=0;
- for(int i=(x.size()-1) ;i>=0 ;i--)
- {
- int f=x[i]-48 , j=y[i]-48 ;
- s=f+j+carry;
- if (s>9)
- {
- h.insert(h.begin() ,((s-10)+48));
- carry=1;
- if (i==0)
- h.insert(h.begin() ,((s/10)+48));
- }
- else
- {
- h.insert(h.begin() ,(s+48));
- carry=0;
- }
- }
- return h;
- }
- string mul (string x , string y)//هنا بتشتغل، جربي كده
- {
- int xm , ym , xs = x.size() , ys = y.size() ,m ;
- string k="";
- for (int i=ys-1 ; i>=0 ; i--)
- {
- string t="";int carry=0;
- for (int f=xs-1 ; f>=0 ; f--)
- {
- xm=x[f]-48; ym =y[i]-48;
- m=(xm*ym)+carry;
- if (m>9)
- {
- t.insert(t.begin() ,((m%10)+48));
- carry=m/10;
- if (f==0)
- t.insert(t.begin() ,((m/10)+48));
- }
- else
- {
- t.insert(t.begin() ,(m+48));
- carry=0;
- }
- }
- for (int d=ys-1-i ; d>0 ; d-- )
- t.insert(t.end() , '0');
- k=add(t,k);
- }
- while( k.size()>1 && k[0]=='0')
- k.erase(0,1);
- return k;
- }
- int main ()
- {
- freopen("myDearInput.in", "r", stdin);
- string x , sum ; int n;
- vector<string> v;
- for (int i=1 ; i<1001 ; i++)
- {
- sum="1";
- x=1;
- while (x> "1")
- {
- sum = mul(sum , x) ;
- x = sub(x);
- }
- v.push_back(sum);
- }
- while (cin >> n)
- {
- cout <<n<<"!"<<endl << v[n] <<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment