[Solved] Time Limit Exceeded [c++] : last digit of each of numbers’ factorial [closed]


This is what you need?

#include <iostream>
#include <vector>

int FactLastDigit(int n) 
{
    if (n > 4)
    {
        return 0;
    }
    else
    {
        long int number = 1;
        for (int i = 1; i <= n; i++)
        {
            number *= i;
        }
        return number % 10;
    }
}


int main()
{
    int t;

    std::cin >> t;

    std::vector<int> T(t);
    for (int i = 0; i < t; i++)
    {
        int n;
        std::cin >> n;
        T[i] = FactLastDigit(n);
    }

    for (int i = 0; i < t; i++)
    {
        std::cout << T[i] << std::endl;
    }
}

0

solved Time Limit Exceeded [c++] : last digit of each of numbers’ factorial [closed]