[BZOJ2242][SDOI2011]计算器
来源:互联网 发布:心理学电脑软件 编辑:程序博客网 时间:2024/06/08 13:22
原题地址
复习了一下离散对数.
偷懒用map,结果差点就T了囧,这个故事再次告诉我们尽量不要用map!
AC code:
#include <cstdio>#include <cmath>#include <map>using namespace std;typedef long long ll;ll t,k,y,z,p;ll work1(ll y,ll q){ if(!q) return 1; ll x=work1(y,q>>1); x=(x*x)%p; if(q&1) x=(x*y)%p; return x;}ll work2(){ return z*work1(y,p-2)%p;}void work3(){ if(!(y%p)){ printf("Orz, I cannot find x!\n"); return ; } ll m=(ll)sqrt(p),inv=work1(work1(y,m),p-2),tz=z%p; map<ll,bool> H; map<ll,ll> ind; for(ll i=0;i<m;i++){ H[work1(y,i)]=1; ind[work1(y,i)]=i; } for(ll i=0;i<=m;i++){ if(i) tz=(tz*inv)%p; if(H[tz]){ printf("%lld\n",i*m+ind[tz]); return ; } } printf("Orz, I cannot find x!\n");}int main(){ scanf("%lld%lld",&t,&k); while(t--){ scanf("%lld%lld%lld",&y,&z,&p); if(k==1) printf("%lld\n",work1(y,z)); else if(k==2){ if(!(y%p)){ printf("Orz, I cannot find x!\n"); continue; } printf("%lld\n",work2()); } else work3(); } return 0;}
0 0
- bzoj2242【sdoi2011】计算器
- [BZOJ2242][SDOI2011]计算器
- [bzoj2242][SDOI2011]计算器
- Bzoj2242:[SDOI2011]计算器:BSGS
- [bzoj2242][SDOI2011]计算器
- 【SDOI2011】【BZOJ2242】计算器
- BZOJ2242 [SDOI2011]计算器
- bzoj2242 [SDOI2011]计算器
- 【BZOJ2242】[SDOI2011]计算器
- 【bzoj2242】【SDOI2011】计算器
- BZOJ2242 SDOI2011 计算器
- BZOJ2242 [SDOI2011]计算器 【BSGS】
- BZOJ2242 [SDOI2011]计算器 题解&代码
- bzoj2242 : [SDOI2011]计算器 [BSGS算法]
- 【bzoj2242】[SDOI2011]计算器 快速幂+exgcd+BSGS
- 【bzoj2242】[SDOI2011]计算器 快速幂+BSGS
- [BZOJ2242][SDOI2011][BSGS][拓展欧几里得]计算器
- bzoj2242 [SDOI2011]计算器(KSM+扩欧+bsgs)
- 机试算法讲解: 第17题 向着炮火前进:二叉排序树咋整啊?
- 博客开篇
- 点球大战(penalty) - 电子科技大学第六届ACM程序设计大赛 初赛
- hdu5319&hdu多校集训第四题
- HDUOJ 1873看病要排队(优先队列)
- [BZOJ2242][SDOI2011]计算器
- 给Vmware进行硬盘(分区)无损扩容 (linux)
- Leetcode# 148 Sort List
- java中打印数组的5种方法
- Arctic Network (POJ 2349)
- Bootstrap组件之导航
- struts框架中的result
- MySql SQLException: Can't create/write to file问题的解决办法
- csharp: Export or Import excel using MyXls