http://www.cnblogs.com/jianglangcaijin/archive/2013/04/26/3045795.html

给p,a,b求a^n==b%p

 #include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<map>
#define ll long long
ll p;
std::map<ll , int> mp;
ll Pow(ll x,ll y){
ll res=;
while (y){
if (y%) res=(res*x)%p;
x=(x*x)%p;
y/=;
}
return res;
}
ll solve(ll a,ll b){
a%=p;
if (a==){
if (b==) return ;
else return -;
}
mp.clear();
ll m=sqrt(p)+,t=,I=;
for (int i=;i<m;i++){
t=t*a%p;
if (!mp[t]) mp[t]=i;
}
mp[]=m+;
ll Im=Pow(a,p--m);
for (int k=;k<m;k++){
int i=mp[I*b%p];
if (i!=){
if (i==m+) i=;
return i+k*m;
}
I=I*Im%p;
}
return -;
}
int main(){
ll a,b;
while (scanf("%lld%lld%lld",&p,&a,&b)!=EOF){
ll ans=solve(a,b);
if (ans==-) puts("no solution");
else printf("%lld\n",ans);
}
}

POJ 2417 Discrete Logging的更多相关文章

  1. BSGS算法+逆元 POJ 2417 Discrete Logging

    POJ 2417 Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4860   Accept ...

  2. poj 2417 Discrete Logging ---高次同余第一种类型。babystep_gaint_step

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2831   Accepted: 1391 ...

  3. POJ 2417 Discrete Logging (Baby-Step Giant-Step)

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2819   Accepted: 1386 ...

  4. POJ - 2417 Discrete Logging(Baby-Step Giant-Step)

    d. 式子B^L=N(mod P),给出B.N.P,求最小的L. s.下面解法是设的im-j,而不是im+j. 设im+j的话,貌似要求逆元什么鬼 c. /* POJ 2417,3243 baby s ...

  5. POJ 2417 Discrete Logging ( Baby step giant step )

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3696   Accepted: 1727 ...

  6. POJ 2417 Discrete Logging 离散对数

    链接:http://poj.org/problem?id=2417 题意: 思路:求离散对数,Baby Step Giant Step算法基本应用. 下面转载自:AekdyCoin [普通Baby S ...

  7. poj 2417 Discrete Logging(A^x=B(mod c),普通baby_step)

    http://poj.org/problem?id=2417 A^x = B(mod C),已知A,B.C.求x. 这里C是素数,能够用普通的baby_step. 在寻找最小的x的过程中,将x设为i* ...

  8. POJ 2417 Discrete Logging BSGS

    http://poj.org/problem?id=2417 BSGS 大步小步法( baby step giant step ) sqrt( p )的复杂度求出 ( a^x ) % p = b % ...

  9. POJ 2417 Discrete Logging(离散对数-小步大步算法)

    Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 1 ...

随机推荐

  1. RMAN学习笔记

    RMAN:如果RMAN连接一个远程数据库,格式:RMAN>rman target sys/jxsrpv@test 1.列出备份信息,所有的备份信息 RMAN>list backup of ...

  2. PHP CI框架下,如果配置NGINX(根目录和子目录两种模式)

    摸索了一会儿,先配置成功,再看看PATH_INFO之类的东东吧. A,根目录: location ~ \.php($|/) { root html; fastcgi_pass ; fastcgi_in ...

  3. eclipse编辑工具小结

    eclipse编辑工具小结 这两天从myeclipse转入eclipse,整体感觉不错,速度更快些,也没在出现各种意外的调试错误.不能断点等情况,并且对整个编辑环境的使用有了更深入的认识,再次对主要几 ...

  4. C++ builder 生成以管理员身份运行的exe

    转自:http://bbs.csdn.net/topics/310225109#post-312177603 ,稍微做了一点修改 创建一个文本文件,命名为123.manifest,内容如下: < ...

  5. 计算机视觉库 SimpleCV

    SimpleCV首页.文档和下载 - 计算机视觉库 - 开源中国社区     计算机视觉库 SimpleCV 编辑/纠错    分享到     新浪微博腾讯微博    已用    +0    收藏 + ...

  6. 特殊权限:SUID,SGID,Sticky

    特殊权限passwd:s SUID: 运行某程序时,相应进程的属主是程序文件自身的属主,而不是启动者:    chmod u+s FILE    chmod u-s FILE        如果FIL ...

  7. PHP批量审核ajax jquery

    var jQuery = $.noConflict(); // alert(jQuery); jQuery(document).ready(function() { /*批量审核*/ jQuery(' ...

  8. Spark常用函数讲解之键值RDD转换

    摘要: RDD:弹性分布式数据集,是一种特殊集合 ‚ 支持多种来源 ‚ 有容错机制 ‚ 可以被缓存 ‚ 支持并行操作,一个RDD代表一个分区里的数据集RDD有两种操作算子:         Trans ...

  9. Find the maximum(规律,大数)

    Find the maximum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  10. cocos2dx 编写shader 遇到 溢出问题

    在 编程语言中,不论什么 数据类型 都有 各种 的 局限,无法 表示 现实世界中的 不论什么 情况. 比如 int ,char 会 溢出,float 会 有 溢出 以及 精度 不准确的 情况. 所以 ...