题意:求fn的第1e10e6项,用广义欧拉降幂了半天都wa,后来才知道时十进制快速幂,nnd第一次知道这玩意
构造矩阵:
|a,b|
|1,0|
然后跑一下十进制快速幂就好了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
typedef pair<pair<ll, ll>, pair<ll, ll> > pll;
template <class T>
void read(T &x);
ll x0, x1, a, b, p;
string s;
pll operator *(const pll &a, const pll &b)
{
return mp( mp((a.first.first * b.first.first % p + a.first.second * b.second.first % p) % p,
(a.first.first * b.first.second % p + a.first.second * b.second.second % p) % p),
mp((a.second.first * b.first.first % p + a.second.second * b.second.first % p) % p,
(a.second.first * b.first.second % p + a.second.second * b.second.second % p) % p) );
}
pll pow(pll a,pll b,int n)
{
while(n)
{
if(n&1) b=b*a;
a=a*a;
n>>=1;
}
return b;
}
pll tenpow()
{
pll res= mp(mp(a, b), mp(1, 0));
pll base=mp(mp(1,0),mp(0,1));
int len=s.size()-1;
for(int i=len;i>=0;i--)
{
base=pow(res,base,s[i]-'0');
res=pow(res,res,9);
}
return base;
}
int main()
{
read(x0), read(x1), read(a), read(b);
cin >> s; read(p);
pll ans=tenpow();
cout << (x1*ans.second.first+x0*ans.second.second)%p<< endl;
return 0;
}
template <class T>
void read(T &x)
{
static char ch;
static bool neg;
for(ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar());
for(x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar());
x = neg ? -x : x;
}