H. The Nth Item(The 2019 Asia Nanchang First Round Online Programming Contest)
题意: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)的更多相关文章
- E.Magic Master(The 2019 Asia Nanchang First Round Online Programming Contest)
直接模拟orhttps://blog.csdn.net/liufengwei1/article/details/100643831
- 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\), ...
- The 2019 Asia Nanchang First Round Online Programming Contest(B,E)
B. Fire-Fighting Hero 题意:一个消防员和多个队伍比赛,比较所有地方的最短路的最大值,消防员最后的值要乘1/C,求胜利的一方的最短路的最大值是多少.一直没读懂正确题意(内疚). 思 ...
- The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item
The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\( ...
- The 2019 Asia Nanchang First Round Online Programming Contest C. Hello 2019(动态dp)
题意:要找到一个字符串里面存在子序列9102 而不存在8102 输出最小修改次数 思路:对于单次询问 我们可以直接区间dpOn求出最小修改次数 但是对于多次询问 我在大部分题解看到的解释一般是用线段树 ...
- The 2019 Asia Nanchang First Round Online Programming Contest C(cf原题,线段树维护矩阵)
题:https://nanti.jisuanke.com/t/41350 分析:先将字符串转置过来 状态转移,因为只有5个状态,所以 i 状态到 j 状态的最小代价就枚举[i][k]->[k][ ...
- The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master
题目链接:https://nanti.jisuanke.com/t/41352 题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了.其实就是个水题,反向模拟就好了, 用队列模拟,反向模拟,它要放 ...
- The 2019 Asia Nanchang First Round Online Programming Contest B. Fire-Fighting Hero
题目链接:https://nanti.jisuanke.com/t/41349 题意:有一个灭火英雄,和一个灭火团队,一个人与一个团队比较. 灭火英雄到其他灭火点的最短路最大值,与一个团队到其他灭火点 ...
- 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 ...
随机推荐
- bzoj5457
城市 HYSBZ - 5457 有n座城市,m个民族.这些城市之间由n-1条道路连接形成了以城市1为根的有根树.每个城市都是某一民族的聚居 地,Master知道第i个城市的民族是A_i,人数是B_i. ...
- trie树(字典树)的部分简单实现
什么是trie树(字典树)? trie树是一种用于快速检索的多叉树结构.和二叉查找树不同,在trie树中,每个结点上并非存储一个元素. trie树把要查找的关键词看作一个字符序列.并根据构成关键词字符 ...
- Pytest学习笔记(三) 在代码中运行pytest
前面介绍的是在cmd中执行pytest,平常我们一般都是通过编译器(如pycharm)来编写用例的,写完用例后,需要调试看看是否能运行,如果每次都切换到cmd中执行,太麻烦. 因此,这一节来说下怎么在 ...
- shell基础之二 bash特性详解
https://blog.51cto.com/13520779/2093146 合格linux运维人员必会的30道shell编程面试题及讲解:https://blog.51cto.com/oldboy ...
- ARTS打卡计划第十六周
Algorithms: https://leetcode-cn.com/problems/min-stack/submissions// Review: https://www.infoq.cn/ar ...
- django 问题总结(八)
1.第一步创建项目,不成功,命令不报错一直不创建文件夹 django-admin.py startproject mysite2 原因: django-admin.py ,py文件的默认打开方式不对, ...
- springboot 配置跨越访问
import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http.H ...
- leetcode题目234.回文链表(快慢指针+辅助空间-简单)
题目描述: 请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O( ...
- JS基础_垃圾回收(GC)
垃圾回收(GC) 程序运行过程中也会产生垃圾,这些垃圾积攒过多以后,会导致程序运行的速度过慢,所以我门需要一个垃圾回收的机制,来处理程序运行过程中产生的垃圾 当一个对象没有任何的变量或属性对它进行引用 ...
- [转]Nginx实现高并发的原理
Nginx 首先要明白,Nginx 采用的是多进程(单线程) & 多路IO复用模型.使用了 I/O 多路复用技术的 Nginx,就成了”并发事件驱动“的服务器. 异步非阻塞(AIO)的详解ht ...