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. 集合-LinkList

    参考:http://www.cnblogs.com/skywang12345/p/3308807.html Consumer.class   消费者接口 参考:https://www.jianshu. ...

  2. 程序包com.sun.image.codec.jpeg不存在解决方法

    https://blog.csdn.net/u011627980/article/details/50436842

  3. 因chmod /usr致使raspberryPi重装

    一.系统安装noobs 设置用户名及密码,设置超级用户root密码:  sudo passwd root,回车后按提示输入两次root的密码(注意,输入时是不会提示*号的,直接输入即可) 二.源及软件 ...

  4. 初涉Git/Github

    初涉Git/Github 第一部分:我的本次作业成果 我自己个人的github地址是:STRSong 我们开发团队小组的github地址是:三组 第二部分:给同学推荐github资源 推荐1 这个推荐 ...

  5. NOIP前必须记住的30句话

    NOIP前必须记住的30句话 1.比赛前一天晚上请准备好你的各种证件,事先查好去往考场的路线2.比赛之前请先调整你的屏幕分辨率到你喜欢的大小3.比赛之前请把编译器的字体调为你平时惯用的字体,尤其是注意 ...

  6. redis hash 类型的操作命令

    redis 文档: https://redis.readthedocs.io/en/2.4/index.html keys * type key --------------------------- ...

  7. SpringCloud中Rabbitmq的使用

    1.pom配置,添加以来jar包 <dependency> <groupId>org.springframework.cloud</groupId> <art ...

  8. time machine不备份指定文件夹

    osx中常常会使用timemachine来备份一些文件,timemachine能够使某个文件夹恢复到之前某个时刻的状态,很的方便.但是备份须要空间,特别是有些我们并不想备份一些无关紧要的文件,比方电影 ...

  9. Python--学习过程

    基础篇 Python基础篇 Python的数据类型 作业总结

  10. react 实现pure render的时候,bind(this)隐患

    react 实现pure render的时候,bind(this)隐患 export default class Parent extends Component { ... render() { c ...