The Nth Item (The 2019 Asia Nanchang First Round Online Programming Contest)

 

 

 

#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef  long long ll;
typedef vector<ll>vec;
typedef vector<vec>mat;
ll M=998244353;
map<ll,ll>cc;
mat mul(mat &A,mat &B){
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++)
    for(int k=0;k<B.size();k++)
    for(int j=0;j<B[0].size();j++)
{
    C[i][j]=(C[i][j]+A[i][k]*B[k][j])%M;
}
return C;
}
mat pow(mat A,ll n)
{
     mat B(A.size(),vec(A.size()));
 for(int i=0;i<A.size();i++)
{
    B[i][i]=1;
}
while(n>0)
{
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n>>=1;

}
return B;
}
map<ll,ll>kkk;
int main()
{
    mat A(2,vec(2));
    A[0][0]=3,A[0][1]=2,A[1][0]=1,A[1][1]=0;
    mat B(2,vec(2));
    ll q,n;
    kkk.clear();
    scanf("%lld%lld",&q,&n);
    ll dns=0,k,kk1;
    while(q--)
    {
           B=pow(A,n);
           ll kk=dns;
          // cout<<B[1][0]<<' '<<n<<endl;;
        dns^=B[1][0];
        kkk[n]=B[1][0];
        n=n^(B[1][0]*B[1][0]);
        if(dns==kk1)
        {
            if(q%2==1)
                dns=kk;
            else
                dns=kk1;
            break;
        }

            kk1=kk;
        //cout<<dns<<endl;
    }
    printf("%lld\n",dns);
}

 

For a series FF:

\displaystyle \begin{gathered} F(0) = 0,F(1) = 1\\ F(n) = 3*F(n-1)+2*F(n-2),(n \geq 2) \end{gathered}F(0)=0,F(1)=1F(n)=3F(n1)+2F(n2),(n2)

 

We have some queries. For each query NN, the answer AA is the value F(N)F(N) modulo 998244353998244353.

Moreover, the input data is given in the form of encryption, only the number of queries QQ and the first query N_1N1are given. For the others, the query N_i(2\leq i\leq Q)Ni(2iQ) is defined as the xor of the previous N_{i-1}Ni1 and the square of the previous answer A_{i-1}Ai1. For example, if the first query N_1N1 is 22, the answer A_1A1 is 33, then the second query N_2N2 is 2 \ xor \ ( 3*3)=112 xor (33)=11.

Finally, you don't need to output all the answers for every query, you just need to output the xor of each query's answer A_1\ xor\ A_2 ... xor\ A_QA1 xor A2...xor AQ.

Input

The input contains two integers, Q, NQ,N1\ \leq \ Q \leq 10^7,0\ \leq\ N \leq 10^{18}1  Q107,0  N1018QQ representing the number of queries and NN representing the first query.

Output:

An integer representing the final answer.

样例输入复制
17 473844410
样例输出复制
903193081

转载于:https://www.cnblogs.com/Shallow-dream/p/11488867.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值