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 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)的更多相关文章
- POJ 2417 Discrete Logging(离散对数-小步大步算法)
Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 1 ...
- POJ 2417 Discrete Logging (Baby-Step Giant-Step)
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2819 Accepted: 1386 ...
- BSGS算法+逆元 POJ 2417 Discrete Logging
POJ 2417 Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4860 Accept ...
- BSGS(Baby Steps,Giant Steps)算法详解
BSGS(Baby Steps,Giant Steps)算法详解 简介: 此算法用于求解 Ax≡B(mod C): 由费马小定理可知: x可以在O(C)的时间内求解: 在x=c之后又会循环: 而BS ...
- POJ 2417 Discrete Logging ( Baby step giant step )
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3696 Accepted: 1727 ...
- POJ 2417 Discrete Logging BSGS
http://poj.org/problem?id=2417 BSGS 大步小步法( baby step giant step ) sqrt( p )的复杂度求出 ( a^x ) % p = b % ...
- POJ 2417 Discrete Logging 离散对数
链接:http://poj.org/problem?id=2417 题意: 思路:求离散对数,Baby Step Giant Step算法基本应用. 下面转载自:AekdyCoin [普通Baby S ...
- poj 2417 Discrete Logging ---高次同余第一种类型。babystep_gaint_step
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2831 Accepted: 1391 ...
- 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* ...
随机推荐
- msp430项目编程37
msp430中项目---usb接口编程37 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- laravel 数据库配置
数据库配置文件为项目根目录下的config/database.php //默认数据库为mysql 'default' => env('DB_CONNECTION', 'mysql'), 'mys ...
- Ubuntu 安装PostgreSQL
安装最新版: sudo apt-get install postgresql 安装完成后,默认会: (1)创建名为"postgres"的Linux用户 (2)创建名为"p ...
- openssl搭建双向认证https
http://www.barretlee.com/blog/2015/10/05/how-to-build-a-https-server/ http://blog.163.com/fangjinbao ...
- ArcCatalog中通过ArcSDE向Oracle数据库中导入数据
将数据导入到Oracle指定的表空间的具体内容如下: 首先,在ArcCatalog中建立指定表空间的数据库连接(要以指定表空间的用户登录): 然后,在ArcCatlog中定位到数据源,选中并拷贝图层; ...
- js -- 侧边悬浮栏特效
github: https://github.com/mybee/float-scroll-page #menu{width: 120px;height: auto; position: fixed; ...
- Oracle RAC环境下怎样更新patch(Rolling Patch)
Oracle RAC数据库环境与单实例数据库环境有非常多共性,也有非常多异性.对于数据库补丁的更新相同如此.都能够通过opatch来完毕.但RAC环境的补丁更新有几种不同的更新方式,甚至于能够 ...
- c 链表之 快慢指针 查找循环节点(转)
上面分析了 根据这张图 推倒出 数学公式. 刚接触 不能一下弄明白.下面结合上面文章的分析.仔细推倒一下 , 一般设置 快指针 速度是 慢指针的2倍.及 快指针每次遍历两个指针, 慢指针每次遍历1个指 ...
- python实现的websocket总结 —— wspy
之前曾有php版的websocket封装包.见Websocket--php实战,近期使用python做一些功能,须要用到对websocket的操作,因此,參照之前的实现,实现了这个python版本号. ...
- Cocoapods Undefined symbols for architecture armv7s\arm64
此类错误 "_OBJC_CLASS_$_AFURLSessionManager", referenced from: 解决的方法 在other linker flags里加入一行 ...