fork download
  1. #include <iostream>
  2. using namespace std;
  3. int fact(int);
  4.  
  5. int func(int n)
  6. {
  7. int z=0;
  8. if(n==0)
  9. return 1;
  10. else
  11. {
  12. for(int r=1;r<=n;r++)
  13. {
  14. z+=(fact(n)/(fact(r)*fact(n-r)))*func(n-r);
  15. }
  16.  
  17. return (fact(n)-z);
  18. }
  19. }
  20.  
  21.  
  22. int fact(int x)
  23. {
  24. int z=1;
  25. for(int j=1;j<=x;j++)
  26. z*=j;
  27. return z;
  28. }
  29.  
  30. int main() {
  31. int k=0,T=0,n=0;
  32. cin>>T;
  33.  
  34. while(T)
  35. {
  36. cin>>n;
  37. T--;
  38. int res=func(n);
  39. cout<<"#"<<n<<" "<<res<<endl;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 2732KB
stdin
1 5
stdout
#5 44