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了一发 最 ...
随机推荐
- Python在函数中使用*和**接收元组和列表
http://blog.csdn.net/delphiwcdj/article/details/5746560
- HDU Ignatius's puzzle
链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1098] 分析: 数学归纳法 f(1) = 18 + ka; 假设f(x) = 5x^13+13x^5+k ...
- Final阶段用户使用报告
此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2477] 组名:可以低头,但没必要 组长:付佳 组员:张俊余 李文涛 孙 ...
- 简言MVC
什么是MVC? MVC是一种代码的组织结构,在一个工程项目中,将代码的数据处理,逻辑单元和交互部分分离开来达到一种低耦合的效果,便于工程的修改.MVC中M代表Model,V代表View,C代表Cont ...
- hadoop-2.7.2 分布式集群搭建
1.机器信息 五台centos 64位机器 2.集群规划 Server Name Hadoop Cluster Zookeeper Ensemble HBase Cluster Hadoop01 ...
- 剑指offer:数组中出现次数超过一半的数
题目描述: 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2 ...
- 安全相关论文--Security and Dependability
安全相关论文--Security and Dependability 所参考的文献来自于Kreutz D, Ramos F M V, Esteves Verissimo P, et al. Softw ...
- 【转帖】Git学习笔记 记录一下
本文内容参考了廖雪峰老师的博文,并做了适当整理,方便大家查阅. 原帖地址 https://wangfanggang.com/Git/git/ 常用命令 仓库初始化 - git init 1 git i ...
- djang-rest-framework学习-day1
1.老套路:setting 设置复制粘贴!,必要库的安装: 一些库安装失败的解决办法:在 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 上找到下载,然后使用用 ...
- CF10D LCIS
题意翻译 求两个串的最长公共上升子序列. 题目描述 This problem differs from one which was on the online contest. The sequenc ...