难点在于n的数据类型不好处理,long long n,_int64 n才是王道,之前用int一直wa,输出%I64d,
n==1||n==2 return 1;
n>2 return (A*Ns(A,B,n-1)+B*Ns(A,B,n-2))%7;
#include<bits/stdc++.h>
using namespace std;
int Ns(int A,int B,_int 64 n)
{
if(n==1||n==2)
return 1;
else
return (A*Ns(A,B,n-1)+B*Ns(A,B,n-2))%7;
}
int main()
{
int a,b;
_int 64 n;
while(~scanf("%d %d %I64d",&a,&b,&n)&&a&&b&&n)
{
int ans=Ns(a,b,n);
cout<<ans<<endl;
}
return 0;
}