JZOJ 5941. 乘
2024-09-20 07:16:44
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;
}
}
最新文章
- 应用程序无法正常启动0xc0150002(windows server 2003)
- Jetty使用教程(四:24-27)—Jetty开发指南
- bootstrap 重写JS的alert、comfirm函数
- 记录一些容易忘记的属性 -- UITabBarController
- 035. asp.netWeb用户控件之四通过用户控件实现投票和结果分析
- DirectX 矩阵
- RESTful服务的版本管理经验 (转)
- [改善Java代码]优先使用整型池
- mysql Event、存储过程、表命令
- linux分区,文件系统,目录结构概述
- Android学习笔记-Adapter基础讲解
- Python学习笔记 - list和tuple
- 你需要一点点CIL
- 西门子S7-200SMART PLC视频教程(百度网盘)
- Apache POI - Java Excel APIs
- 保留最新N份备份目录脚本
- hive 函数
- python input 与raw_input函数的区别
- 转载:pyqt线程间通过 信号/槽 通信
- timerWithTimeInterval 方法详用
热门文章
- JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
- Object中的clone方法
- js:JavaScript中的ActiveXObject对象
- VBA注意事项
- 深入理解linux源码安装三板斧
- NO.006-2018.02.11《卜算子&#183;我住长江头》宋代:李之仪
- 成都夏季招聘会IT行业缺口大!
- [18/11/7] Java的基础概念
- Nmap的基础知识
- 2018.11.22 mac中";允许所有安装来源";的命令 &; Mac窗口标题显示文件的路径