fuck Section 3

master
大蒟蒻 9 years ago
parent 51276e82ca
commit 7f86d9e1f2

@ -0,0 +1,67 @@
#include <cmath>
#include <cstdio>
#include <cstring>
typedef long long i64;
void exgcd(i64 a, i64 b, i64 &x, i64 &y)
{
b == 0 ? (x = 1, y = 0) : (exgcd(b, a % b, y, x), y -= (a / b) * x);
}
struct HashTable
{
static const size_t sz = 500009;
i64 idx[sz], val[sz];
void init()
{
memset(idx, -1, sizeof(idx));
memset(val, -1, sizeof(val));
}
void insert(i64 i, i64 v)
{
i64 j = i % sz;
while (idx[j] != -1 && idx[j] != i)
{
j++;
if (j == sz)
j = 0;
}
if (val[j] == -1)
{
idx[j] = i;
val[j] = v;
}
}
i64 find(i64 i)
{
i64 j = i % sz;
while (idx[j] != -1 && idx[j] != i)
{
j++;
if (j == sz)
j = 0;
}
return val[j];
}
} H;
int main()
{
for (i64 a, b, c; ~scanf("%lld%lld%lld", &c, &a, &b) && a | b | c;)
{
H.init();
i64 m = i64(ceil(sqrt(c))), d = 1;
for (int i = 0; i < m; i++, d = d * a % c)
H.insert(d, i);
i64 res = 1, x, y;
bool flag = false;
for (i64 i = 0; i < m && !flag; i++, res = res * d % c)
{
exgcd(res, c, x, y);
x = (x * b % c + c) % c;
i64 j = H.find(x);
if (j != -1)
printf("%lld\n", i * m + j), flag = true;
}
if (!flag)
puts("no solution");
}
return 0;
}

@ -176,7 +176,7 @@ AC 自动机模板题,注意统计答案时,每个节点只能统计一次
Manacher 模板题
\codeinput[Palindrome]{assets/day2/poj3974.cpp}
\section{day3 简单数学}
说是简单数学其实我后半部分也没看懂等明天来补欠债。20170215\\
说是简单数学其实我后半部分也没看懂\\
\subsection{整除及剩余}
\paragraph{整除定义}
$a,b$是两个整数,且$b\neq0$.如果存在整数$c$,使得$a=bc$,则称$a$$b$整除,或$b$整除$a$,记作$b|a$。此时,又称$a$$b$的倍数,$b$$a$的因子。
@ -314,7 +314,14 @@ Manacher 模板题
$$x^{p-1}\equiv 1\pmod{p}$$于是有
$$\forall p\in\mathbb{P},x\in\mathbb{Z}\to x^{-1}\equiv x^{p-2}\pmod{p}$$
使用快速幂即可计算。
\subsection{待续:高次不定方程}
\subsection{离散对数问题}
解这鬼东西:$$A^x\equiv B\pmod{C}$$ 这玩意有个性质,$A^x\mod C$有周期性,最大周期不超过$C$,我想这是显然的(除非你没上过小学)。
\paragraph{$C\in\mathbb{P}$}
普通的BSGS
\subparagraph{\href{http://poj.org/problem?id=2417}{POJ2417} - Discrete Logging} 模板题
\codeinput[Primitive Roots]{assets/day3/poj2417.cpp}
\paragraph{$C\in\mathbb{N_+}$}
待续
\subsection{原根}
\paragraph{}
$$n>1,a\in\mathbb{Z},gcd(a,n)=1\to\exists r\in[1,n],a^r\equiv1\pmod{n}$$ $r$的最小整数值称为$a$$n$的阶,记为$Ord_n(a)$

Loading…
Cancel
Save