标签:iostream nbsp code color miss size str names span
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 171693 Accepted Submission(s): 42372
1 #include <stdio.h>
2 #include <math.h>
3 #include <string.h>
4 #include <map>
5 #include <iostream>
6 #include <algorithm>
7 int w[100];
8 using namespace std;
9 int main()
10 {
11 int a,b,n,i,flag,first,end,j;
12 while(cin>>a>>b>>n&&(a||b||n))
13 {
14 flag=0;
15 w[0]=1;
16 w[1]=1;
17 w[2]=1;
18 for(i=3;i<=n&&!flag;i++)
19 {
20 w[i]=(a*w[i-1]+b*w[i-2])%7;
21 for(j=2;j<=i-1;j++)
22 {
23 if(w[i]==w[j]&&w[i-1]==w[j-1])
24 {
25 first=j-1;
26 end=i-1;
27 flag=1;
28 break;
29 }
30 }
31 }
32 if(flag)
33 printf("%d\n",w[first+(n-end)%(end-first)]);
34 else
35 printf("%d\n",w[n]);
36 }
37 return 0;
38 }
标签:iostream nbsp code color miss size str names span
原文地址:http://www.cnblogs.com/--lr/p/6869941.html