Factorial Small Number | ZS

PHOTO EMBED

Tue Sep 07 2021 09:04:19 GMT+0000 (UTC)

Saved by @zs #c++

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define take(n) ll int n;cin>>n
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;

int main()
{
    // Zubin Shah
    int N;
    cin>>N;
    while(N--)
    {
        take(n);
        vector<int> vect;
        vect.pb(1);
        ll carry=0;
        int number_of_digits=1;
        rep(i,2,n+1){
            rep(j,0,number_of_digits){
                ll temp=(vect[j]*i)+carry;
                vect[j]=temp%10;
                carry=temp/10;
            }
            while(carry>0){
                ll temp=carry%10;
                vect.pb(temp);
                carry/=10;
                number_of_digits++;
            }
        }
        rrep(i,number_of_digits-1,0){
            cout<<vect[i];
        }
        cout<<endl;
    }


return 0;
}
content_copyCOPY