传送门

关于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. MySQL 创建自定义函数(1)

    1. 创建测试自定义函数(1) CREATE DEFINER=`dbdh`@`localhost` FUNCTION `test`.`sp_function_dbdh_three`() RETURNS ...

  2. [iOS] 初探 iOS8 中的 Size Class

    本文转载至  http://www.itnose.net/detail/6112176.html   以前和安卓的同学聊天的时候,谈到适配一直是一个非常开心的话题,看到他们被各种屏幕适配折磨的欲仙欲死 ...

  3. 【BZOJ3837】[Pa2013]Filary 随机化神题

    [BZOJ3837][Pa2013]Filary Description 给定n个正整数,从中挑出k个数,满足:存在某一个m(m>=2),使得这k个数模m的余数相等. 求出k的最大值,并求出此时 ...

  4. EasyDarwin开源流媒体服务器实现RTSP直播同步输出MP4、RTMP、HLS的方案思路

    背景 近期跟开源团队商量,想在EasyDarwin上继续做一些功能扩展,目前EasyDarwin开源流媒体服务器只能够实现高效的RTSP推流直播转发/分发功能,输入与输出都是RTSP/RTP流,不能够 ...

  5. EasyHLS直播在Linux非root用户运行时出现无法写文件的问题解决mkdir 0777

    今天在Github上收到一个用户反馈的EasyHLS在linux上非root用户调用时,无法写目录的问题:https://github.com/EasyDarwin/EasyHLS/issues/3, ...

  6. EasyHLS实现将IPCamera摄像机的RTSP流转成HLS(ts+m3u8)直播输出

    本文转自:http://www.cnblogs.com/babosa/p/6033039.html EasyHLS EasyHLS是EasyDarwin开源流媒体团队开发的一款HLS打包库,接口非常简 ...

  7. 剑指Offer:树的子结构【26】

    剑指Offer:树的子结构[26] 题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 解题思路 分为两步: 第一步:在树A中找到和树B的根节点的值一 ...

  8. 利用AutoLayout适配滚动视图和表视图

    1.新增一个contentView,设置为与滑动视图的父视图等高等宽. 2.利用代码 if(_MyTestTableView.frame.size.height != _MyTestTableView ...

  9. tensorflow 线性回归解决 iris 2分类

    # Combining Everything Together #---------------------------------- # This file will perform binary ...

  10. BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数

    BZOJ_4026_dC Loves Number Theory _主席树+欧拉函数 Description  dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯 竭 ...