传送门

关于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 ;
}

spoj3105 MOD - Power Modulo Inverted(exbsgs)的更多相关文章

  1. 【SPOJ】Power Modulo Inverted(拓展BSGS)

    [SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...

  2. MOD - Power Modulo Inverted(SPOJ3105) + Clever Y(POJ3243) + Hard Equation (Gym 101853G ) + EXBSGS

    思路: 前两题题面相同,代码也相同,就只贴一题的题面了.这三题的意思都是求A^X==B(mod P),P可以不是素数,EXBSGS板子题. SPOJ3105题目链接:https://www.spoj. ...

  3. 「SPOJ 3105」Power Modulo Inverted

    「SPOJ 3105」Power Modulo Inverted 传送门 题目大意: 求关于 \(x\) 的方程 \[a^x \equiv b \;(\mathrm{mod}\; p) \] 的最小自 ...

  4. HDU 6623"Minimal Power of Prime"(数学)

    传送门 •题意 给你一个大于 1 的正整数 n: 它可以分解成不同的质因子的幂的乘积的形式,问这些质因子的幂中,最小的幂是多少. •题解 定义 $ans$ 表示最终答案: ①如果 $ans \ge 5 ...

  5. ExaWizards 2019 English D - Modulo Operations(DP)

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Snuke has a blackb ...

  6. Luogu4195 【模板】exBSGS(exBSGS)

    如果a和p互质,用扩欧求逆元就可以直接套用普通BSGS.考虑怎么将其化至这种情况. 注意到当x>=logp时gcd(ax,p)是一个定值,因为这样的话每个存在于a中的质因子,其在ax中的出现次数 ...

  7. Integer’s Power HDU - 3208(容斥原理)

    找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接 ...

  8. [USACO2002][poj1945]Power Hungry Cows(启发式搜索)

    Power Hungry CowsTime Limit: 1000MS Memory Limit: 30000K Total Submissions: 4570 Accepted: 1120 Desc ...

  9. leetcode342——Power of Four(C++)

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...

随机推荐

  1. OTL中文乱码 OTL UTF8

    在用unixODBC连接MySQL的时候字符编码是由odbc支持的,不须要C++编译OTL的时候加上什么编译条件. 假设你的数据库使用的编码是UTF-8,你要从这个数据库读数据.并且还要将结果放到这个 ...

  2. Building REST services with Spring

    https://spring.io/guides/tutorials/bookmarks/

  3. bluebird-api简介及demo

    var Promise = require("bluebird"); var fs = require("fs"); //方法Promise化 var read ...

  4. Dockder的CS模式:

    Docker的守护进程一直运行, yw1989@ubuntu:~$ ps -ef | grep docker : 就是docxker的守护进程 root : ? :: /usr/bin/dockerd ...

  5. signal函数理解或者void (*signal(int signum,void(*handler)(int)))(int)理解

    把void (*signal(int signum,void(*handler)(int)))(int)分成两部分: typedef void (*sighandler_t)(int); sighan ...

  6. oracle rac常用的网络检查命令

    oracle的集群管理软件和数据库对私网依赖性很大,很多集群问题最后都可以归结到网络层面. 当集群出现问题时检查网络信息是必要的. 1.查看MTU的大小,确认所有节点的公网和私网网卡的MTU大小相同 ...

  7. dij+堆优化

    写这个dij+堆优化的原因是有些地方卡SPFA,只能搞这个: 香甜的奶油: #include<iostream> #include<cstdio> #include<cs ...

  8. Facebook图片存储系统Haystack——存小文件,本质上是将多个小文件合并为一个大文件来降低io次数,meta data里存偏移量

    转自:http://yanyiwu.com/work/2015/01/04/Haystack.html 一篇14页的论文Facebook-Haystack, 看完之后我的印象里就四句话: 因为[传统文 ...

  9. 2016.4.23浙江省赛(zoj3936 zoj3938 zoj3940 zoj3944 zoj3946 zoj3947 )

    A      Apples and Ideas Time Limit: 2 Seconds      Memory Limit: 65536 KB "If you have an apple ...

  10. c++之cin/cin.get/cin.getline()详解

    C++输入过程中,是把输入加载到缓冲区中,然后对缓冲区中的字符进行读取.cin,cin,get(),cin.getline()三个函数虽然都能进行数据读取,但是它们对缓冲区内数据的处理方法是不同的(如 ...