联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvb29vb29vb29l/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""> 思路:与上题不同.这道题不要求m是素数.是利用扩展Baby Step Giant S…
Mod Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 96 Accepted Submission(s): 38   Problem Description   The picture indicates a tree, every node has 2 children.  The depth of the nodes whos…
http://acm.hdu.edu.cn/showproblem.php?pid=2815 //解 K^D ≡ N mod P #include<map> #include<cmath> #include<cstdio> #include<iostream> using namespace std; map<int,int>mp; typedef long long LL; void read(int &x) { x=; char c=…
题目链接 直接用模板好了.实在不行,反正有队友啊~~~~ #include<bits/stdc++.h> using namespace std; typedef long long LL; map<LL,LL>mp; LL qpow(LL x,LL n,LL mod) //求x^n%mod { LL ret=; ) { ) ret=ret*x%mod; x=x*x%mod; } return ret; } LL gcd(LL a, LL b) { return b? gcd(b,…
Accepted 406MS 8576K 2379 B C++/** 这里加了一点限制,,大体还是一样的,, **/ #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; long long a,b,n; ; bool Hash[maxn]; long long val[…
不会,先搁着…… http://blog.csdn.net/acm_cxlove/article/details/7832197…
题目大意就是求 a^x = b(mod c) 中的x 用一般的baby step giant step 算法会超时 这里参考的是http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 map平衡树查找值 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <map> us…
先给出我所参考的两个链接: http://hi.baidu.com/aekdycoin/item/236937318413c680c2cf29d4 (AC神,数论帝  扩展Baby Step Giant Step解决离散对数问题) http://blog.csdn.net/a601025382s/article/details/11747747 Baby Step Giant Step算法:复杂度O( sqrt(C) ) 我是综合上面两个博客,才差不多懂得了该算法. 先给出AC神的方法: 原创帖…
不理解Baby Step Giant Step算法,请戳: http://www.cnblogs.com/chenxiwenruo/p/3554885.html #include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #define SIZE 99991 /* POJ 3243 AC 求解同余方程: A^x=B(mod C) */ using namespace…
1. 引入 Baby Step Giant Step算法(简称BSGS),用于求解形如\(a^x\equiv b\pmod p\)(\(a,b,p\in \mathbb{N}\))的同余方程,即著名的离散对数问题. 本文分为 \((a,p)=1\) 和 \((a,p)\neq 1\) 两种情况讨论. 2. 方程 \(a^x\equiv b \pmod p\) 的解性 因为若 \(a^{x}\equiv a^{x+n}\pmod p\),则 \(a^{x+i}\equiv a^{x+n+i}\).…