Metamath Proof Explorer


Theorem modgcd

Description: The gcd remains unchanged if one operand is replaced with its remainder modulo the other. (Contributed by Paul Chapman, 31-Mar-2011)

Ref Expression
Assertion modgcd M N M mod N gcd N = M gcd N

Proof

Step Hyp Ref Expression
1 zre M M
2 nnrp N N +
3 modval M N + M mod N = M N M N
4 1 2 3 syl2an M N M mod N = M N M N
5 zcn M M
6 5 adantr M N M
7 nncn N N
8 7 adantl M N N
9 nnre N N
10 nnne0 N N 0
11 redivcl M N N 0 M N
12 1 9 10 11 syl3an M N N M N
13 12 3anidm23 M N M N
14 13 flcld M N M N
15 14 zcnd M N M N
16 mulneg1 M N N M N N = M N N
17 mulcom M N N M N N = N M N
18 17 negeqd M N N M N N = N M N
19 16 18 eqtrd M N N M N N = N M N
20 19 ancoms N M N M N N = N M N
21 20 3adant1 M N M N M N N = N M N
22 21 oveq2d M N M N M + M N N = M + N M N
23 mulcl N M N N M N
24 negsub M N M N M + N M N = M N M N
25 23 24 sylan2 M N M N M + N M N = M N M N
26 25 3impb M N M N M + N M N = M N M N
27 22 26 eqtrd M N M N M + M N N = M N M N
28 6 8 15 27 syl3anc M N M + M N N = M N M N
29 4 28 eqtr4d M N M mod N = M + M N N
30 29 oveq2d M N N gcd M mod N = N gcd M + M N N
31 14 znegcld M N M N
32 nnz N N
33 32 adantl M N N
34 simpl M N M
35 gcdaddm M N N M N gcd M = N gcd M + M N N
36 31 33 34 35 syl3anc M N N gcd M = N gcd M + M N N
37 30 36 eqtr4d M N N gcd M mod N = N gcd M
38 zmodcl M N M mod N 0
39 38 nn0zd M N M mod N
40 33 39 gcdcomd M N N gcd M mod N = M mod N gcd N
41 33 34 gcdcomd M N N gcd M = M gcd N
42 37 40 41 3eqtr3d M N M mod N gcd N = M gcd N