bzoj千题计划246:bzoj2242: [SDOI2011]计算器
http://www.lydsy.com/JudgeOnline/problem.php?id=2242
#include<map>
#include<cmath>
#include<cstdio> using namespace std; int y,z,p; map<int,int>mp; int Pow(int a,int b,int m)
{
int ans=;
for(;b;a=1LL*a*a%m,b>>=)
if(b&) ans=1LL*ans*a%m;
return ans;
} int gcd(int a,int b) { return !b ? a : gcd(b,a%b); } void exgcd(int a,int b,long long &x,long long &y)
{
if(!b) { x=; y=; return; }
exgcd(b,a%b,y,x); y-=a/b*x;
} void bsgs()
{
mp.clear();
int m=ceil(sqrt(p));
int mul=z;
//mp[z]=0;
for(int j=;j<=m;++j)
{
mul=1LL*y*mul%p;
mp[mul]=j;
}
int am=Pow(y,m,p);
mul=;
for(int j=;j<=m;++j)
{
mul=1LL*mul*am%p;
if(mp.find(mul)!=mp.end())
{
printf("%d\n",j*m-mp[mul]);
return;
}
}
puts("Orz, I cannot find x!");
} int main()
{
int T,k;
scanf("%d%d",&T,&k);
if(k==)
while(T--)
{
scanf("%d%d%d",&y,&z,&p);
printf("%d\n",Pow(y,z,p));
}
else if(k==)
{
long long x0,y0;
int g;
while(T--)
{
scanf("%d%d%d",&y,&z,&p);
g=gcd(y,p);
if(z%g) puts("Orz, I cannot find x!");
else
{
y/=g; p/=g;
exgcd(y,p,x0,y0);
x0=(x0%p+p)%p;
x0=x0*z/g%p;
printf("%lld\n",x0);
}
}
}
else
while(T--)
{
scanf("%d%d%d",&y,&z,&p);
if(!(y%p)) puts("Orz, I cannot find x!");
else bsgs();
}
return ;
}
bzoj千题计划246:bzoj2242: [SDOI2011]计算器的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划254:bzoj2286: [Sdoi2011]消耗战
http://www.lydsy.com/JudgeOnline/problem.php?id=2286 虚树上树形DP #include<cmath> #include<cstdi ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
随机推荐
- 【ORACLE】碎片整理
alter table test enable row movement; alter table test shrink space; execute dbms_stats.gather_table ...
- NetBeans的(默认)快捷键
NetBeans的(默认)快捷键 1.完成代码:ctrl+\ //任何地方按下此组合键,均会提示相应的参考字段: 2.错误提示:alt + enter //顾名思义,当系统报错时,按下此组合可以查看 ...
- Mysql的基本操作(一)增、删、改
创建/增加(create创建,alter字段操作,insert插入) 创建数据库 create database 数据库名称 charset=utf8; # 例: create database te ...
- Azkaban集群部署
一.部署模式 solo-server模式 (使用内置h2存储元数据): two-server模式 (1个webServer,1个execServer在同一服务器上,使用mysql存储元数据): mu ...
- Python初学者随笔Week1
Python从入门到放弃 本文主要是描述的是作为初学者对python学习的过程与经历分享,包括一些历程的分享与重要的时间节点记录,对于python学习的笔记与心得. 如果你也是初学者,我们可以一起学习 ...
- 阿里云ubuntu16.04安装ruby
0x0 准备 环境:阿里云轻量服务器ubuntu16.04 目的:安装beef需要的ruby环境 更新软件 sudo apt-get update sudo apt-get upgrade sudo ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 2013337朱荟潼 Linux第四章读书笔记——进程调度
第4章 进程调度 0. 总结 调度:调度是一个平衡的过程.一方面,它要保证各个运行的进程能够最大限度的使用CP:另一方面,保证各个进程能公平的使用CPU. 调度功能:决定哪个进程运行以及进程运行多长时 ...
- Beta冲刺——day7
Beta冲刺--day7 作业链接 Beta冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602134 王龙 ...
- PAT 1017 A除以B
https://pintia.cn/problem-sets/994805260223102976/problems/994805305181847552 本题要求计算A/B,其中A是不超过1000位 ...