前言

什么鬼畜玩意,扶我起来,我要用__int128,这辈子都不珂能用龟速乘的...

真香。

题解

我们知道这个模数是个神奇的东西

\(2305843008676823040 = 2^{29} \times 3 \times 5 \times 17 \times 65537\)

所以\(\varphi(2305843008676823040) = 2^{28} \times 2 \times 2^2 \times 2^4 \times 2^{16} = 2^{51}\)

\(a^{\varphi(n)}=1\ (mod\ n)\),所以在\(60\)次以内,该数\(mod 2305843008676823040\)一定会变为\(1\)。

用线段树维护序列,再加一个龟速乘,解决问题

#include <cstdio>
#define ll long long const ll MOD = 2305843008676823040ll;
ll s[1000001];
bool flg[1000001]; long long read(){
long long x = 0; int zf = 1; char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
} inline ll mul(ll x, ll y){
ll res = 0;
for ( ; y; y >>= 1ll, (x <<= 1ll) %= MOD)
if(y & 1)
(res += x) %= MOD;
return res;
} void build(int pos, int l, int r){
if (l == r){
s[pos] = read();
flg[pos] = ((s[pos] == 1 || !s[pos]) ? 1 : 0);
return ;
}
int mid = (l + r) >> 1;
build(pos << 1, l, mid);
build(pos << 1 | 1, mid + 1, r);
flg[pos] = flg[pos << 1] & flg[pos << 1 | 1];
s[pos] = (s[pos << 1] + s[pos << 1 | 1]) % MOD;
} ll query(int pos, int l, int r, int x, int y){
if (x <= l && r <= y && flg[pos])
return s[pos];
if (l == r){
ll res = s[pos];
ll tmp = mul(s[pos], s[pos]);
if (tmp == s[pos])
flg[pos] = 1;
s[pos] = tmp;
return res;
}
int mid = (l + r) >> 1;
ll res;
if (y <= mid)
res = query(pos << 1, l, mid, x, y);
else if (x > mid)
res = query(pos << 1 | 1, mid + 1, r, x, y);
else{
res = query(pos << 1, l, mid, x, y);
(res += query(pos << 1 | 1, mid + 1, r, x, y)) %= MOD;
}
s[pos] = (s[pos << 1] + s[pos << 1 | 1]) % MOD;
flg[pos] = flg[pos << 1] & flg[pos << 1 | 1];
return res
} int main(){
int n = read(), m = read();
for (register int i = 1; i <= 1000000; ++i) flg[i] = 1;
build(1, 1, n);
while (m--){
int l = read(), r = read();
ll res = query(1, 1, n, l, r) % MOD;
printf("%lld\n", res);
}
return 0;
}

最新文章

  1. [PHP] 自定义错误处理
  2. ARC指南1 - strong和weak指针
  3. 史上最用心的iOS App上架流程【转】
  4. hdu 4405Aeroplane chess(概率DP)
  5. 怎么解决/bin/sh: arm-linux-gcc: not found make
  6. 1990-D. 幻方
  7. 关于Azure存储账户中存储虚拟机VHD文件的注意事项
  8. java中创建对象 类名 对象名=new 类名(); 后面的()什么意思
  9. [译]C++如何切分字符串
  10. 动态修改UINavigationBar的背景色
  11. H264 编码详解
  12. 九度OJ 题目1371:最小的K个数
  13. Android_使用getIdentifier()获取资源Id
  14. C++ 版本的split_string
  15. Gate One
  16. MFC: 获得关机消息;阻止Windows关机
  17. 【CSS3】transition过渡和animation动画
  18. Eclipse使用Maven2的一次环境清理记录
  19. python之文件目录操作
  20. HeadFIrst Ruby 第二章总结 methods and classes

热门文章

  1. pycharm运行测试用例遇到错误:ZeroDivisionError: float division by zero的原因
  2. 1.parrot os 3.5-----nmap-----katoolin--zenmap
  3. 浅谈vue学习之组件通信
  4. Linux 后台执行python或者java代码的命令
  5. js Functor Copy
  6. MySQL-快速入门(4)MySQL函数
  7. JS中创建10个a标签,点击弹出对应的序号
  8. [2019上海网络赛J题]Stone game
  9. activemq热备与消息丢失
  10. linux(centeros)svn的安装