循环实现数组递归
递推数列
http://www.nowcoder.com/questionTerminal/d0e751eac618463bb6ac447369e4aa25
#include <stdio.h> int main(){ int a0,a1,p,q,k; int i; while(scanf("%d %d %d %d %d",&a0,&a1,&p,&q,&k)!=EOF){ int a[k+1]; a[0]=a0; a[1]=a1; for(i=2;i<k+1;i++) a[i]=(p*a[i-1]+q*a[i-2])%10000; printf("%d\n",a[k]); } }
循环的时间复杂度低于递归(•̀ᴗ•́)و