标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 153132 Accepted Submission(s): 37335
#include<stdio.h> int fun(int,int,int ); int main() { int a,b; long long int n; while(scanf("%d %d %lld",&a,&b,&n)!=EOF&&(a||b||n)) { int arr[50]={1,1}; for(int i=2;i<=48;i++) arr[i]=(a*arr[i-1]+b*arr[i-2])%7; if(n%49==0) printf("%d",arr[48]); else printf("%d\n",arr[n%49-1]); } return 0; }
周期是7*7==49~yeah!
周期递归做会超时~毕竟n的规模是10^8,所以时间复杂度必须是O(n)!!!!!
标签:
原文地址:http://www.cnblogs.com/hellohacker/p/5727478.html