A. Template was removed along && expanding Europe inversion yuan template
blog:https://blog.csdn.net/m0_37579232/article/details/81428065
https://blog.csdn.net/m0_37579232/article/details/89810566
int gcd(int x,int y)
{
return y?gcd(y,x%y):x;
}
// exgcd inversion yuan to expand in Europe
int exgcd(int a,int b,int &x,int &y)//calc ax+by=gcd(a,b);
{
if(b==0)
{
x=1,y=0;
return a;
}
int g=exgcd(b,a%b,y,x);
y-=a/b*x;
return g;
}
int exgcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1,y=0;
return a;
}
else
{
int g=exgcd(b,a%b,y,x);
y-=a/b*x;
return g;
}
}
Note the following:
1. If the required solutions ax + by solution of the equation k = variable, if and only if k | when gcd (a, b) solvability
2. find the k ax + Solution by =, first find ax + by = gcd (a, b) solution,
then x0 = x * k / gcd ( a, b), y0 = y * k / gcd (a, b); the desired solution
3. how to get the indefinite equation the smallest positive integer solution? ?
x = ((x * K / gcd (a, b))% (b / gcd (a, b)) + (b / gcd (a, b)))% (b / gcd (a, b));
II. Euler function
https://baike.baidu.com/item/%E6%AC%A7%E6%8B%89%E5%87%BD%E6%95%B0/1944850?fr=aladdin
https://blog.csdn.net/sentimental_dog/article/details/52002608
/ Euler function
// Method a: definition follows directly
int Euler (n-int)
{
int = n-RES, n-A =;
for (int I = 2; I * I <= A; I ++)
{
IF (A I == 0%)
RES = RES / I * (. 1-I);
the while (A == 0% I)
A / I =;
}
IF (A>. 1) RES = RES / A * (. 1-A) ;
return RES;
}
// method two: calculated Euler mesh while completing the Euler function +
int m [N], Phi [N], P [N], NUMP;
// store the i-th m is prime Euler Phi function value [i] of the i-number storage
// p [i] stored in the i-th prime number, p memory array size nump
void Calc ()
{
Phi [. 1] =. 1;
for (int i = . 1; I <= n-; I ++)
{
IF (m [I])!
{
P [++ NUMP] = I;
Phi [I] = I-. 1;
}
the else
{
for (int J =. 1; J <= && P NUMP [J] * I <= n-; J ++)
{
m [P [I] I *] =. 1;
if (i% p [j] == 0)
Non [i * p [j]] = non [i] * p [j];
else
fees [i * p [j]] = non [i] * (p [j] -1);
}
}
}
}
III. Seeking sieve prime number
https://www.luogu.org/problemnew/solution/P3383
Example: https://www.luogu.org/problem/P3383
#include<cstdio>
#include<cstring>
#define N 10000002
using namespace std;
int n,m,pn,t;
bool prime[N];
int Prime[N];
inline void Sieve()
{
memset(prime,true,sizeof(prime));
prime[0]=prime[1]=false;
for(int i=2;i<=n;i++)
{
if(prime[i])
{
Prime[pn++]=i;
}
for(int j=0;j<pn&&Prime[j]*i<=n;j++)
{
prime[Prime[j]*i]=false;
if(i%Prime[j]==0)
break;
}
}
return;
}
int main()
{
scanf("%d %d",&n,&m);
Sieve();
for(int i=1;i<=m;i++)
{
scanf("%d",&t);
if(prime[t])
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
IV. Multiplicative function
https://baike.baidu.com/item/%E7%A7%AF%E6%80%A7%E5%87%BD%E6%95%B0/8354949?fr=aladdin
V. Fermat's Little Theorem
For a prime p and integer a, if (a, b) = 1, then a power of p-1 film p I 1;
If a, b, c is any integer of 3, m is a positive integer and (m, c) = 1, then when a · c≡b · c (mod m ), there a≡b (mod m).
Proved that: a · c≡b · c (mod m) can be obtained ac-bc≡0 (mod m) can be obtained (ab) · c≡0 (mod m ). Since (m, c) = 1 i.e. m, c coprime, c can go about, a- b≡0 (mod m) can be obtained a≡b (mod m). [2]
Provided m is an integer and m> 1, b is an integer and (m, b) = 1. If a [1], a [2 ], a [3], a [4], ... a [m] is a complete residual system modulo m, then b · a [1], b · a [2], b · a [3], b · a [4], ... b · a [m] constitute a complete residual system of modulo m.
Proof: If two integer b · a [i] and b · a [j] congruence i.e. b · a [i] ≡b · a [j] (mod m) is present .. (i> = 1 && j > = 1), according to the Lemma 1 has a [i] ≡a [j] (mod m). The remaining lines completely defined understood this is not possible, so there is no two integers b · a [i] and b · a [j] congruence.