传送门

关于exbsgs是个什么东东可以去看看yyb大佬的博客->这里

 //minamoto
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#define ll long long
#define GG {puts("No Solution");}
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline ll read(){
#define num ch-'0'
char ch;bool flag=;ll res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
map<ll,ll> mp;
inline ll gcd(ll a,ll b){
if(!b) return a;
while(b^=a^=b^=a%=b);
return a;
}
inline ll ksm(ll a,ll b,ll p){
ll res=;
while(b){
if(b&) (res*=a)%=p;
(a*=a)%=p,b>>=;
}
return res;
}
inline void ex_BSGS(ll y,ll z,ll p){
if(z==) return (void)(puts(""));
int k=,a=;
while(true){
int d=gcd(y,p);if(d==) break;
if(z%d) return (void)(GG);
z/=d,p/=d,++k,a=1ll*a*y/d%p;
if(z==a) return (void)(printf("%d\n",k));
}
mp.clear();
int m=sqrt(p)+;
for(int i=,t=z;i<m;++i,t=1ll*t*y%p) mp[t]=i;
for(int i=,tt=ksm(y,m,p),t=1ll*a*tt%p;i<=m;++i,t=1ll*t*tt%p){
int j=mp.find(t)==mp.end()?-:mp[t];
if(j>=&&i*m-j+k>=) return (void)(printf("%d\n",i*m-j+k));
}
GG;
}
int main(){
// freopen("testdata.in","r",stdin);
while(true){
int x=read(),z=read(),k=read();
if(x==&&z==&&k==) break;
ex_BSGS(x,k,z);
}
return ;
}

最新文章

  1. Scrapy爬取自己的博客内容
  2. zorka源码解读之Beanshell与zorka的交互实现
  3. BSGS模版 a^x=b ( mod c)
  4. 【NOIP模拟题】【二分】【倍增】【链表】【树规】
  5. vim 配合管道过滤多行记录
  6. [转载]TexturePacker 如何使用自带的加密功能及在cocos2dx中的使用
  7. sql语句的基本操作
  8. Socket异步发送的同步控制
  9. sklearn两种保存模型的方式
  10. pubwin 客户端会员无法自助结账的排查方法
  11. StringBuilder[] 作为数组如何使用
  12. 精通CSS+DIV网页样式与布局--滤镜的使用
  13. 使用Rotativa在ASP.NET Core MVC中创建PDF
  14. IIS发布错误及解决
  15. C++ 日期时间使用
  16. Android getWidth和getMeasuredWidth
  17. cpu占用过高排查
  18. imanager一些常用方法汇总
  19. 【Nginx】服务器中HTTP 301跳转到带www的域名的方法
  20. 计算机上面常用的计算单位 &amp; 个人计算机架构与接口设备

热门文章

  1. asp.net c# select 动态加载数据
  2. tomcat servlet JSP common gateway interface 公共网关接口
  3. a completely rewritten architecture of Hadoop cluster
  4. 为编译器的实现者提供一个精确的定义:ANSI C
  5. 基于地理位置信息的traceroute
  6. (转)SDP协议概述
  7. TCP/IP-ICMP-Ping-Traceroute
  8. ansible 文件模块,很实用
  9. Ansible 动态获取主机列表
  10. 在线判题系统hustoj的搭建