样例能过,T 在第一个点……
#include<iostream>
#include<cstdio>
#include<cstring>
#define int long long
using namespace std;
struct mt{
int n,a[3][3];
inline void m0(int x)//初始化为全 0 矩阵
{n=x;memset(a,0,sizeof(a));}
inline void m1(int x)//初始化为单位矩阵
{m0(x);for(int i=1;i<=n;i++)a[i][i]=1;}
mt operator =(mt x)//赋值
{
n=x.n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=x.a[i][j];
return *this;
}
mt operator *(mt x)
{
mt res;
res.m0(n);
for(int i=1;i<=n;i++)
for(int k=1;k<=n;k++)//ikj优化
for(int j=1;j<=n;j++)
res.a[i][j]=res.a[i][j]+a[i][k]*x.a[k][j];
return res;
}
mt operator ^(int x)
{
mt tmp;
if(!x){tmp.m1(n);return tmp;}
if(x&1) return (*this)*((*this)^(x^1));
tmp=(*this)^(x>>1);
return tmp*tmp;
}
};
inline int work(int x,int y,int z)
{
mt A;
A.n=2;
A.a[1][1]=x;
A.a[1][2]=1;
A.a[2][1]=-y;
A.a[2][2]=0;
mt res=A^(z-1);
return res.a[1][1]*x+res.a[2][1]*2;
}
int p,q,r;
signed main()
{
while(scanf("%lld%lld%lld",&p,&q,&r)==3)
printf("%lld\n",work(p,q,r));
return 0;
}