Project Euler #160: Factorial trailing digits

  • + 1 comment

    Hi, can someone help me with my code. I could pass only 1 test case. For other test cases it say terminated due to timeout.

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    
    int main() {
        int base,n;
       // cout <<" enter base" <<endl;
        cin >> base;
       // cout <<"Enter the value of n"<<endl;
        cin >> n;
        int arr[n];
      //  cout <<"Enter the array"<<endl;
        for(unsigned int i=0;i<n;i++)
        {
         cin >> arr[i];   
            
        }
        
        for(int i=0;i<n;i++)
            {
      long long unsigned  int fact = 1;
            for(unsigned int j=1;j<=arr[i];j++)
                {
                fact=fact*j;
            }
          //  cout << fact << " ";
            while((fact % base) == 0)
                {
                fact=fact/10;
            }
            cout << (fact%100000) <<endl;
        }
        return 0;
    }