d. 式子B^L=N(mod P),给出B、N、P,求最小的L。

s.下面解法是设的im-j,而不是im+j。

设im+j的话,貌似要求逆元什么鬼

c.

/*
POJ 2417,3243
baby step giant step
a^x=b(mod n) n是素数或不是素数都可以
求解上式 0<=x<n的解
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std; #define MOD 76543
int hs[MOD],head[MOD],next[MOD],id[MOD],top; void insert(int x,int y){
int k=x%MOD;
hs[top]=x,id[top]=y,next[top]=head[k],head[k]=top++;
} int find(int x){
int k=x%MOD;
for(int i=head[k];i!=-;i=next[i])
if(hs[i]==x)
return id[i];
return -;
} int BSGS(int a,int b,int n){
memset(head,-,sizeof(head));
top=;
if(b==)return ;
int m=sqrt(n*1.0),j;
long long x=,p=;
for(int i=;i<m;++i,p=p*a%n)insert(p*b%n,i);
for(long long i=m;;i+=m){
if((j=find(x=x*p%n))!=-)return i-j;
if(i>n)break;
}
return -;
} int main(){ int P,B,N;
int ans; while(~scanf("%d%d%d",&P,&B,&N)){
ans=BSGS(B,N,P);
if(ans==-){
printf("no solution\n");
}
else{
printf("%d\n",ans);
}
} return ;
}

参考:http://www.cnblogs.com/yuiffy/p/3877381.html

http://www.cnblogs.com/kuangbin/archive/2013/08/24/3278852.html

POJ - 2417 Discrete Logging(Baby-Step Giant-Step)的更多相关文章

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

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

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

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

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

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

  4. BSGS(Baby Steps,Giant Steps)算法详解

    BSGS(Baby Steps,Giant Steps)算法详解 简介: 此算法用于求解 Ax≡B(mod C): 由费马小定理可知: x可以在O(C)的时间内求解:  在x=c之后又会循环: 而BS ...

  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 BSGS

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

  7. POJ 2417 Discrete Logging 离散对数

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

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

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

  9. 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* ...

随机推荐

  1. 【Eclipse】eclipse部署web项目至本地的tomcat但在webapps中找不到

    clipse部署web项目至本地的tomcat但在webapps中找不到 1.发现问题 在我的 eclipse 中有个Dynamic Web Project(动态web项目),在本地的 tomcat ...

  2. JFinal Weixin 1.6发布【转】

    原文:http://www.oschina.net/news/69495/jfinal-weixin-1-6-released#rd 继JFinal 2.1发布之后,再来一发JFinal Weixin ...

  3. T2639 约会计划 codevs

    http://codevs.cn/problem/2639/ 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而 ...

  4. CPU 内存 硬盘的区别

    第一点:CPU 是处理器,内存和硬盘是存储器,受CPU 的控制.  第二点:由于内存的速度很快,在电脑运行的过程中,CPU通常只与内存交换数据,但内存断电数据就会全部丢失,因此电脑使用硬盘作为主要的存 ...

  5. VC++下编译Libgeotiff(含Libtiff)

    转自原文Win10+VC++下编译Libgeotiff(含Libtiff)详细图文教程 GeoTiff是包含地理信息的一种Tiff格式的文件.Libgeotiff就是一个操作GeoTiff文件的库.同 ...

  6. Protostuff序列化和反序列化使用说明

    原文:http://blog.csdn.net/zhglance/article/details/56017926 google原生的protobuffer使用起来相当麻烦,首先要写.proto文件, ...

  7. mysql PROCEDURE ANALYSE() 用法

    PROCEDURE ANALYSE() 会让 MySQL 帮你去分析你的字段和其实际的数据,并会给你一些有用的建议.只有表中有实际的数据,这些建议才会变得有用,因为要做一些大的决定是需要有数据作为基础 ...

  8. STL源代码分析--deque

    一.deque的中控器       deque是连续空间(至少逻辑上看来如此),连续线性空间总令我们联想到array或vector.array无法成长,vector虽可成长,却仅仅能向尾端成长.并且其 ...

  9. SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir

    读写sd卡中的文件依照例如以下步骤:1调用Environment的getExternalStorageState()方法推断手机上是否插入了sd卡.而且应用程序具有读写SD卡的能力 //假设手机已经插 ...

  10. 远程唤醒UP Board

    前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我的博客: http://www.cnblogs.co ...