Jak mogę skrócić czas tego programu, ponieważ SPOJ p[okazuje że przekroczono limit czasu ?
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
long int silnia(int n) {
if (n == 0) {
return 1;
}
else {
return n * silnia(n - 1);
}
}
int main() {
int ile, a, wynik = 1;
string v;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> ile;
wynik = silnia(ile);
string x = to_string(wynik); // Konwersja z int na string
if (x[1] == NULL)
cout << "0 " << x[x.length() - 1] << endl;
else
cout << x[x.length() - 2] << " " << x[x.length() - 1] << endl;
wynik = 1;
}
}