BSGS算法是meet in the middle思想的一种应用,参考Yveh的博客我学会了BSGS的模版和hash表模板,,, 现在才会hash是不是太弱了,,, #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node{ static const int mo=100007; int a[100010],v…
Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数. Input 输入包含多组数据. 第一行包含两个正整数T,K分别表示数据组数和询问类型(对于一个测试点内的所有数据,询问类型相同). 以下行每行包含三个正整数y,z,p,描述一个询问. Output 对于每个询问,输出一行答案.对…
污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][Status][Discuss] Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数…
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description 小Y发现,数学中有一个很有趣的式子: X^Y mod Z = K 给出X.Y.Z,我们都知道如何很快的计算K.但是如果给出X.Z.K,你是否知道如何快速的计算Y呢? Input 本题由多组数据(不超过20组),每组测试数据包含一行三个整数X.Z.K(0 <= X, Z, K <= 109). 输入文…
kuangbin的BSGS: c为素数: #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; ; i = next[i]) if(hs[i] =…
2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数. Input 输入包含多组数据. 第一行包含两个正整数T,…
题意:给你一个分数,求它在二进制下的循环节的长度,还有第一个循环节从哪一位开始. For example, x = 1/10 = 0.0001100110011(00110011)w and 0001100110011 is a preperiod and 00110011 is a period of 1/10. 思路一: 我们可以观察一下1/10这组数据,按照二进制转换法(乘二法),我们可以得到: 1/10 2/10 4/10 8/10 16/10 32/10 ... 然后都分子都尽可能减去…
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, Y, Z, we all know how to figure out K fast. However, given X, Z, K, could you figure out Y fast? Input Input data consists of no more than 20 test ca…
Problem Description The picture indicates a tree, every node has 2 children. The depth of the nodes whose color is blue is 3; the depth of the node whose color is pink is 0. Now out problem is so easy, give you a tree that every nodes have K chil…
没什么好说的... --------------------------------------------------------------------- #include<cstdio> #include<cmath> #include<map> using namespace std; typedef long long ll; int MOD; void gcd(int a, int b, int& d, int& x, int…
Given a prime P, 2 <= P < 2 31, an integer B, 2 <= B < P, and an integer N, 1 <= N < P, compute the discrete logarithm of N, base B, modulo P. That is, find an integer L such that B L == N (mod P) Input Read several lines of input, each…
3239: Discrete Logging Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 729 Solved: 485[Submit][Status][Discuss] Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B < P, and an integer N, 2 <= N < P, compute the discrete logar…
每次把gcd(a,c)提到前面,直到a,c互质,然后就是普通BSGS了 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #define LL long long using namespace std; struct hashtable{ static const int N=577399; int tot,hash…
BSGS算法,预处理出ϕ(c)−−−−√内的a的幂,每次再一块一块的往上找,转移时将b乘上逆元,哈希表里O(1)查询即可 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<map> #define LL long long long long a,b,c,m; bool bo=0; std…