I think that it is well known approach (i remember similar thing in example to recursive function)
Examples from spoj work fine but something is wrong apparently in test.
include
using namespace std;
int smfact(int a);
int main()
{
int a;
cin >> a;
for (int i = 0; i<a; i++)
{
int x;
cin >> x;
int iloczyn;
iloczyn = smfact(x);
cout << iloczyn << endl;
}
return 0;
}
int smfact(int a)
{
if (a == 1) return a;
return a*smfact(a - 1);
}