| 记录编号 | 
        44163 | 
        评测结果 | 
        AAAAAAAAAAAAAAAAAAAA | 
    
    
        | 题目名称 | 
        1163.数列求值 | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         Makazeu | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        0.007 s  | 
    
    
        | 提交时间 | 
        2012-10-17 07:56:13 | 
        内存使用 | 
        3.28 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		#include <cstdio>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
int A,B,N,num[10][10];
int circle[10][10]={0};
queue<int> q;int cs,clen,Be,Af;
vector<int> ans;
int main()
{
	freopen("sequenceb.in","r",stdin);
	freopen("sequenceb.out","w",stdout);
	scanf("%d %d %d\n",&A,&B,&N);
	for(int i=0;i<7;i++)
		for(int j=0;j<7;j++)
			num[i][j]=-1;
	q.push(1); q.push(1);
	int before,after,now;
	ans.push_back(1);
	ans.push_back(1);
	for(int i=3;;i++)
	{
		before=q.front(); q.pop();
		after=q.front(); q.pop();
		now=(A*after+B*before)%7;
		if(num[before][after]!=-1)
		{
			ans.push_back(now);
			if(i>=N)
			{
				printf("%d\n",ans[N-1]);
				return 0;
			}
			cs=circle[before][after];
			clen=i-cs; Be=before; Af=after;
			break;
		}
		circle[before][after]=i;
		num[before][after]=now;
		q.push(after);q.push(now);
		ans.push_back(now);
	}	
	int modder=(N-cs+1)%clen;
	if(modder==0) modder=clen;
	while(q.size()) q.pop();
	q.push(Be); q.push(Af); 
	for(int i=1;i<=modder;i++)
	{
		before=q.front(); q.pop();
		after=q.front(); q.pop();
		now=(A*after+B*before)%7;
		q.push(after);q.push(now);
	}
	printf("%d\n",now);
	return 0;
}