这个递推的程序哪里错了?
Function f(n) is recursively defined as:• f(n) = f(n-1) + f(n-3), n > 3
• f(n) = n, n <= 3
Write a program to calculate f(n) modulo m.
n <= 10000, 2 <= m <= 10000.
#include<stdio.h>
long f(long n)
{ long p;
if(n<3) p=n;
else p=f(n-1)+f(n-3);
return p;
}
int main()
{
long n,m,a;
while(scanf("%ld%ld",&n,&m)&&(n||m))
{
while((n<1)||(n>10000)||(m>10000)||(m<2))
{
scanf("%ld%ld",&n,&m);
}
a=f(n);
printf("%ld\n",a%m);
}
return 0;
}
n>=50就卡住了