The Nth Item

思路:

先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出。

但是还不够,我们先对\(n\)欧拉降幂,然后求base为\(\sqrt{1e9}\)的快速幂,预处理一些东西,就可以类似O(1)求出了。

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int MOD = 998244353;
const LL fsqrt17 = 473844410;
const LL sqrt17 = MOD-fsqrt17;
const LL inv2 = (MOD+1)/2;
const LL invsqrt17 = 438914993;
const int N = 4e4 + 5;
LL p[N], pp[N], P[N], PP[N], q, n;
LL f(LL n) {
return (p[n%(N-1)]*P[n/(N-1)])%MOD;
}
LL F(LL n) {
return (pp[n%(N-1)]*PP[n/(N-1)])%MOD;
}
int main() {
p[0] = pp[0] = 1;
for (int i = 1; i < N; ++i) p[i] = p[i-1]*(3+sqrt17)%MOD*inv2%MOD, pp[i] = pp[i-1]*(3+fsqrt17)%MOD*inv2%MOD;
P[0] = PP[0] = 1;
for (int i = 1; i < N; ++i) {
P[i] = P[i-1]*p[N-1]%MOD;
PP[i] = PP[i-1]*pp[N-1]%MOD;
}
scanf("%lld %lld", &q, &n);
LL res = 0;
for (int i = 1; i <= q; ++i) {
LL ans = -(f(n%(MOD-1))-F(n%(MOD-1)))*invsqrt17%MOD;
ans = (ans + MOD) % MOD;
res ^= ans;
n ^= ans*ans;
}
printf("%lld\n", res);
return 0;
}

最新文章

  1. Android服务开机自启动
  2. 【bzoj1061】 Noi2008—志愿者招募
  3. 【转】javascript 中that的含义示例介绍
  4. 排序之希尔排序(shell sort)
  5. sqoop1.99.4 JAVA API操作
  6. 通过 Javacore 了解线程运行状况
  7. MVC神韵---你想在哪解脱!(十七)
  8. ZOJ 1025 Wooden Sticks(快排+贪心)
  9. 字符串(后缀数组):POJ 3415 Common Substrings
  10. Collection Views and Building Custom Layouts-备
  11. ubuntu17 安装中文输入法
  12. rabbitmq3.6.5镜像集群搭建以及haproxy负载均衡
  13. postgreSQL使用杂谈
  14. Fiddler导出Jmeter脚本
  15. xcode工程编译错误:The maximum number of apps for free development profiles has been reached.
  16. 浅谈STM32L071硬件I2C挂死
  17. java 異常抛出 throw 與 return
  18. Sangfor_AC用户不在线但在“在线用户管理”里有显示
  19. 为什么CPU的主频止步于4GHz?
  20. Web安全测试漏洞场景

热门文章

  1. RabbitMQ官方教程一Hello World(GOLANG语言实现)
  2. tornodo学习之路
  3. Django学习过程中遇到的问题
  4. java绘图(基于Graphics2D)
  5. EFCore 调试远程SqlServer数据库提示信号灯超时时间已到
  6. Java设计模式:23种设计模式(转)
  7. Web基础和servlet基础
  8. QT 读写.ini配置文件
  9. 下载安装Git,学习笔记
  10. Eclipse设置每行的最大字符数