题意:https://nanti.jisuanke.com/t/41355

给出N1,计算公式:A=F(N)Ni=Ni-1 ^ (A*A),F为类斐波那契需要矩阵快速幂的递推式。

求第k个N。

思路:

发现从大约1e5个数开始N交替出现,到一定位置%2即可。(or正解:https://blog.csdn.net/qq_41848675/article/details/100667808   or

https://blog.csdn.net/jk_chen_acmer/article/details/100635672   or   map记忆化)

 #include<bits/stdc++.h>
using namespace std;
//const int maxn=1000005;
using namespace std;
typedef long long ll;
const int N = ;//矩阵大小
//ll k;
const long long mod=(long long );
struct Mat
{
ll mat[N][N];
Mat operator*(const Mat a)const
{
Mat b; memset(b.mat, , sizeof(b.mat));
for (int i = ; i < N; i++)
for (int j = ; j < N; j++)
for (int k = ; k < N; k++)
b.mat[i][j] = (b.mat[i][j] + (mat[i][k]) *(a.mat[k][j])) % mod;
return b;
}
}; ll phi(ll x)//求欧拉
{
ll res=x;
for(ll i=;i*i<=x;i++)
{
if(x%i==)
{
res=res/i*(i-);
while(x%i==) x/=i;
}
}
if(x>) res=res/x*(x-);
return res;
}
Mat Pow(Mat m, ll k)
{
//if(k==1) return 1;
Mat ans;
memset(ans.mat, , sizeof(ans.mat));
for (int i = ; i < N; i++)
ans.mat[i][i] = ;
while (k)
{
if (k & ) ans = ans*m;
k >>= ;
m = m*m;
}
return ans;
} ll que[*];
int head=,tail= ;
int main() { ll phi_mod=phi(mod);
Mat m;
int q;
ll n,ans;
scanf("%d%lld",&q,&n);
//printf("\n%d %lld\n",q,n);
Mat f;
m.mat[][]=;m.mat[][]=;
m.mat[][]=;m.mat[][]=;
f.mat[][]=;//x1
f.mat[][]=;//x0
f = Pow(m, (n-)%phi_mod)*f;
ans=f.mat[][];
//printf("%lld %lld\n",n,ans);
que[head]=ans; //printf("%lld",f.mat[0][0]);
/*
* 10000000 1000000000000000000
* */
for (register int i = ; i <= q; i++) {
//init(m);
//memset(f.mat, 0, sizeof(f.mat));
n = n ^ (f.mat[][] * f.mat[][]); if (n == ) {
f.mat[][] = ;
} else if (n == ) {
f.mat[][] = ;
} else {
m.mat[][] = ;
m.mat[][] = ;
m.mat[][] = ;
m.mat[][] = ;
f.mat[][] = ;//x1
f.mat[][] = ;//x0 f = Pow(m, (n - ) % phi_mod) * f; }
ans = ans ^ f.mat[][];
//printf("%lld %lld\n", n, ans); que[tail++]=ans;
if(tail-head>)
{
head++;
if(que[head]==que[head+]&&que[head+]==que[head++])
{
int tmp=q-i;
if(tmp%)
{
ans=que[head];
}
else
{
ans=que[head+];
}
break;
}
} }
printf("%lld\n",ans);
return ;
} /*
* 858251072
*
* 245284867829898842 447003402
485245887812443738 1008229130
*
*
*
*
* */

H. The Nth Item(The 2019 Asia Nanchang First Round Online Programming Contest)的更多相关文章

  1. E.Magic Master(The 2019 Asia Nanchang First Round Online Programming Contest)

    直接模拟orhttps://blog.csdn.net/liufengwei1/article/details/100643831

  2. The 2019 Asia Nanchang First Round Online Programming Contest

    传送门 A. Enju With math problem 题意: 给出\(a_1,\cdots,a_{100}\),满足\(a_i\leq 1.5*10^8\). 现在问是否存在一个\(pos\), ...

  3. The 2019 Asia Nanchang First Round Online Programming Contest(B,E)

    B. Fire-Fighting Hero 题意:一个消防员和多个队伍比赛,比较所有地方的最短路的最大值,消防员最后的值要乘1/C,求胜利的一方的最短路的最大值是多少.一直没读懂正确题意(内疚). 思 ...

  4. The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item

    The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\( ...

  5. The 2019 Asia Nanchang First Round Online Programming Contest C. Hello 2019(动态dp)

    题意:要找到一个字符串里面存在子序列9102 而不存在8102 输出最小修改次数 思路:对于单次询问 我们可以直接区间dpOn求出最小修改次数 但是对于多次询问 我在大部分题解看到的解释一般是用线段树 ...

  6. The 2019 Asia Nanchang First Round Online Programming Contest C(cf原题,线段树维护矩阵)

    题:https://nanti.jisuanke.com/t/41350 分析:先将字符串转置过来 状态转移,因为只有5个状态,所以 i 状态到 j 状态的最小代价就枚举[i][k]->[k][ ...

  7. The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master

    题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放 ...

  8. The 2019 Asia Nanchang First Round Online Programming Contest B. Fire-Fighting Hero

    题目链接:https://nanti.jisuanke.com/t/41349 题意:有一个灭火英雄,和一个灭火团队,一个人与一个团队比较. 灭火英雄到其他灭火点的最短路最大值,与一个团队到其他灭火点 ...

  9. The 2019 Asia Nanchang First Round Online Programming Contest B Fire-Fighting Hero(阅读理解)

    This is an era of team success, but also an era of heroes. Throughout the ages, there have been nume ...

随机推荐

  1. shell 读取文本并访问mysql/redis

    #!/bin/bash File="redeemcode.csv" #File=$ database="d_redeem_info" echo "ch ...

  2. DOM元素

    元素的三种创建方法 1.doumrnt.write(可以写类名,各种表情属性)       script写在哪里就创建在哪 <button>点我</button> <sc ...

  3. HDFS 特殊权限位

    HDFS 特殊权限位 标签(空格分隔): Hadoop 之前对HDFS更或者说是对Linux中文件的权限没有进行一个完整的学习,只是知道有所有者.所属组和其它权限,具体到某个人的权限有读(r).写(w ...

  4. 我的zshrc文件设置备份

    # If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin: ...

  5. python操作Elasticsearch (一、例子)

    E lasticsearch是一款分布式搜索引擎,支持在大数据环境中进行实时数据分析.它基于Apache Lucene文本搜索引擎,内部功能通过ReST API暴露给外部.除了通过HTTP直接访问El ...

  6. 同源策略和Ajax跨域访问

    1. 什么是同源策略 理解跨域首先必须要了解同源策略.同源策略是浏览器上为安全性考虑实施的非常重要的安全策略.    何谓同源:        URL由协议.域名.端口和路径组成,如果两个URL的协议 ...

  7. git 命令简洁手册

    1.从当前目录初始化 git init 2.对文件进行跟踪 或  将已跟踪的文件放到暂缓区 或 把有冲突的文件标记为已解决状态 git add <file> 3.从现有仓库克隆 git c ...

  8. 【批处理】ren命令_批量重命名文件

    [ren命令] 说明:ren是“rename(重命名)”的简写: 命令:REN [Drive:][path] <old filename> <new filename> 解释: ...

  9. 发布机制-灰度发布-例子:QZone

    ylbtech-发布机制-灰度发布-例子:QZone QZone是另外一个采用灰度发布的例子.大家都知道,QZone在过去的一年中改进是巨大的,从以前慢悠悠的老爷爷变成了一个充满青春活力的小伙子.其中 ...

  10. VBA 刷新数据透视表

    Sub pjCount() Dim r As Long r = Sheets("Inquery").[A65536].End(xlUp).Row ActiveSheet.Pivot ...