题意:
给p,b,n求最小的l使b^l==n(mod p)。
题意:
相当于在0~p-1内搜索l满足同余式,baby_step,giant_step相当于分块的二分搜索,设m=sqrt(p), 则将p分为m*m,在m块内每块进行m个数的二分搜索。
代码://poj 2417
//sep9
#include
#include
#include
using namespace std;
...
分类:
编程语言 时间:
2015-04-15 17:11:42
阅读次数:
174
#include
#include
#include
#include
using namespace std;
typedef __int64 LL;
LL gcd(LL a, LL b)
{
return b ? gcd(b, a%b) : a;
}
LL pow_mod(LL a, LL p, LL n)
{
LL ans = 1;
while(p)
{
if(p&1)
...
分类:
其他好文 时间:
2015-03-16 17:51:51
阅读次数:
164
题目大意就是求 a^x = b(mod c) 中的x用一般的baby step giant step 算法会超时这里参考的是http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4map平衡树查找值 1 #include 2 #incl....
分类:
编程语言 时间:
2015-02-02 01:53:56
阅读次数:
252
一道裸的BSGS题目(叫baby step, giant step)从爱酱的blog里学来的,是一个很神的根号算法。如果我们有hash的工具的话,就是O(sqrt(p))的,这里又用了一个map所以是O(sqrt(p) * log(sqrt(p))) 1 /*********************...
分类:
其他好文 时间:
2015-01-30 22:15:38
阅读次数:
123
题目大意:给定P,B,N,求最小的L使B^L≡N (mod P) (P是质数)
裸的BSGS。。。 练练手吧- -
#include
#include
#include
#include
#include
#define M 100100
#define INF 0x3f3f3f3f
using namespace std;
typedef pair abcd;
long long ...
分类:
其他好文 时间:
2015-01-20 12:07:39
阅读次数:
204
给定同余式,求它在内的所有解,其中总是素数。分析:解本同余式的步骤如下 (1)求模的一个原根 (2)利用Baby Step Giant Step求出一个,使得,因为为素数,所以有唯一解。 (3)设,这样就有,其中,那么得到。 (4)求出所有的,可以知道一共有个解,我们求出所有的,然后排个序即...
分类:
其他好文 时间:
2014-10-29 16:36:21
阅读次数:
250
考虑一个问题:A^x%p=B,给定A,B,p,求x的最小非负整数解。
在p是质数的情况下,这个问题比较简单。
A^x=B(mod P) (P is a Prime, A,B
Let m = floor(sqrt(P))
Put A^0,A^1,...A^(m-1) into HashSet(You Can Also Use Map in STL),for Example M[A^i]=i....
分类:
编程语言 时间:
2014-10-28 13:55:30
阅读次数:
271
Mod TreeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 96 Accepted Submission(s): 38Problem Desc...
分类:
其他好文 时间:
2014-10-07 18:21:23
阅读次数:
209
Discrete LoggingTime Limit:5000MSMemory Limit:65536KTotal Submissions:3696Accepted:1727DescriptionGiven a prime P, 2 k^i^m * k^j = n (mod p ) -> ...
分类:
其他好文 时间:
2014-10-07 16:05:23
阅读次数:
205
高次同余方程。 BL == N (mod P)求解最小的L。由于数据范围很大,暴力不行这里用到baby_step,giant_step算法。意为先小步,后大步。令L=i*m+j (m=ceil(sqrt(p-1))),那么原式化为 B^(i*m)*B^j==N(MOD P)————》B^j===N*...
分类:
其他好文 时间:
2014-08-30 16:16:19
阅读次数:
244