牛客多校 generator 1

题意:求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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值