Time limit Exceded(TLE) on problem no. 1083
I use recursion method for solve this problem.But it verdict as TLE. How can i improve my code? Here is my code>
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int fac(int a,int b)
{
if(a==1)
return 1;
else if(a<0 || a==0)
return 2;
else
return a*fac(a-b,b);
}
int main()
{
int n,k,a;
long long int sum;
while(scanf("%d %d",&n,&k)!=EOF)
{
sum=1;
if((n>=1 && n<=10)&& (k>=1 && k<=20)){
sum=sum*fac(n,k);
cout<<sum<<endl;
}
}
return 0;
}