Sample Input

Sample Input1:
4 3 9 6
5 8 7 7

Sample Output

Sample Output1:
0
做法(转自JZOJ):考虑 a 是定值, 而 b ≤ 1012 , 我们可以预处理 a 的 0...106 次方与 1 ∗ 106 , 2 ∗ 106 ...106 ∗ 106 次 方, 询问时把 b 切成两半, 拼起来就是答案. 这样询问就是 O(1) 的. 复杂度 O(q + 106 ).
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#define LL long long
#define N 1000007
using namespace std;
LL a,p,q,k;
LL b,m,l,C,b1;
LL ans,mia[N],la[N]; LL ksm(LL a,LL b){
LL root=,base=a;
while(b){
if (b&) root*=base,root%=p;
base*=base;
base%=p;
b>>=;
}
return root;
} int main(){
freopen("pow.in","r",stdin);
freopen("pow.out","w",stdout);
scanf("%lld%lld%lld%lld",&a,&p,&q,&k);
scanf("%lld%lld%lld%lld",&b,&l,&m,&C);
mia[]=;
la[]=;
LL g=;
for(int i=;i<=g;++i)
mia[i]=(mia[i-]*a)%p,la[i]=ksm(mia[i],g)%p;
for(int i=;i<=q;++i){
b1=(b*m+C)%l;
ans=ans^((mia[b1%g]*la[b1/g])%p);
if (i%k==) printf("%lld\n",ans);
b=b1;
}
}

最新文章

  1. 应用程序无法正常启动0xc0150002(windows server 2003)
  2. Jetty使用教程(四:24-27)—Jetty开发指南
  3. bootstrap 重写JS的alert、comfirm函数
  4. 记录一些容易忘记的属性 -- UITabBarController
  5. 035. asp.netWeb用户控件之四通过用户控件实现投票和结果分析
  6. DirectX 矩阵
  7. RESTful服务的版本管理经验 (转)
  8. [改善Java代码]优先使用整型池
  9. mysql Event、存储过程、表命令
  10. linux分区,文件系统,目录结构概述
  11. Android学习笔记-Adapter基础讲解
  12. Python学习笔记 - list和tuple
  13. 你需要一点点CIL
  14. 西门子S7-200SMART PLC视频教程(百度网盘)
  15. Apache POI - Java Excel APIs
  16. 保留最新N份备份目录脚本
  17. hive 函数
  18. python input 与raw_input函数的区别
  19. 转载:pyqt线程间通过 信号/槽 通信
  20. timerWithTimeInterval 方法详用

热门文章

  1. JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
  2. Object中的clone方法
  3. js:JavaScript中的ActiveXObject对象
  4. VBA注意事项
  5. 深入理解linux源码安装三板斧
  6. NO.006-2018.02.11《卜算子&#183;我住长江头》宋代:李之仪
  7. 成都夏季招聘会IT行业缺口大!
  8. [18/11/7] Java的基础概念
  9. Nmap的基础知识
  10. 2018.11.22 mac中&quot;允许所有安装来源&quot;的命令 &amp; Mac窗口标题显示文件的路径