spoj3105 MOD - Power Modulo Inverted(exbsgs)
关于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)的更多相关文章
- 【SPOJ】Power Modulo Inverted(拓展BSGS)
[SPOJ]Power Modulo Inverted(拓展BSGS) 题面 洛谷 求最小的\(y\) 满足 \[k\equiv x^y(mod\ z)\] 题解 拓展\(BSGS\)模板题 #inc ...
- MOD - Power Modulo Inverted(SPOJ3105) + Clever Y(POJ3243) + Hard Equation (Gym 101853G ) + EXBSGS
思路: 前两题题面相同,代码也相同,就只贴一题的题面了.这三题的意思都是求A^X==B(mod P),P可以不是素数,EXBSGS板子题. SPOJ3105题目链接:https://www.spoj. ...
- 「SPOJ 3105」Power Modulo Inverted
「SPOJ 3105」Power Modulo Inverted 传送门 题目大意: 求关于 \(x\) 的方程 \[a^x \equiv b \;(\mathrm{mod}\; p) \] 的最小自 ...
- HDU 6623"Minimal Power of Prime"(数学)
传送门 •题意 给你一个大于 1 的正整数 n: 它可以分解成不同的质因子的幂的乘积的形式,问这些质因子的幂中,最小的幂是多少. •题解 定义 $ans$ 表示最终答案: ①如果 $ans \ge 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 ...
- Luogu4195 【模板】exBSGS(exBSGS)
如果a和p互质,用扩欧求逆元就可以直接套用普通BSGS.考虑怎么将其化至这种情况. 注意到当x>=logp时gcd(ax,p)是一个定值,因为这样的话每个存在于a中的质因子,其在ax中的出现次数 ...
- Integer’s Power HDU - 3208(容斥原理)
找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接 ...
- [USACO2002][poj1945]Power Hungry Cows(启发式搜索)
Power Hungry CowsTime Limit: 1000MS Memory Limit: 30000K Total Submissions: 4570 Accepted: 1120 Desc ...
- 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 ...
随机推荐
- jsp页面中文乱码解决方案
一.JSP页面中文乱码 在JSP页面中,中文显示乱码有两种情况:一种是HTML中的中文乱码,另一种是在JSP中动态输出的中文乱码. 先看一个JSP程序: <%@ page language=&q ...
- Netty聊天器(实战一):从0开始实战100w级流量应用
Java 聊天程序(百万级流量实战一):系统介绍 疯狂创客圈 Java 分布式聊天室[ 亿级流量]实战系列之14 [博客园 总入口 ] 源码IDEA工程获取链接:Java 聊天室 实战 源码 写在前面 ...
- it starts (“forks”) a new process for each connection.
PostgreSQL: Documentation: 10: 1.2. Architectural Fundamentals https://www.postgresql.org/docs/10/st ...
- webapp 打包
输入您的WAP网址,技术员马上帮您封装APP! APP人工打包-智睿软件_app打包_苹果app发布_app 上架_ios 上架_封装app_网站转app_安卓发布 http://app.niuhu1 ...
- 使用Swift开发iOS项目、UI创建、方法调用
//1.root控制器的创建 var rootCtrl =RootViewController() var root:UINavigationController =UIN ...
- Go语言string,int,int64 ,float之间类型转换方法
(1)int转string ? 1 2 s := strconv.Itoa(i) 等价于s := strconv.FormatInt(int64(i), 10) (2)int64转string ? 1 ...
- php memcache知识点总结
$memcache = new Memcache; $memcache->connect('localhost',11211) or die('Could not connect'); //me ...
- 【mysql】mysql innodb 配置详解
MySQL innodb 配置详解 innodb_buffer_pool_size:这是InnoDB最重要的设置,对InnoDB性能有决定性的影响.默认的设置只有8M,所以默认的数据库设置下面Inno ...
- html页面表格导出到excel总结
转载:http://www.cnblogs.com/liuguanghai/archive/2012/12/31/2840262.html <table id="tableExcel& ...
- 启动jmeter报错
启动jmeter.bat时报错