# notes from the live session on 14 Dec 2020. # copyig the numbers from the slides na=663847 nb=622411 nc=499153 ra=94601 rb=380254 rc=451506 # setting up for CRT N=na*nb*nc N M1=N/na M1 M1 % na # the number equals M1 % na; this formula computes the inverse mod na Mod(577271^-1,na) v1=423684 e1=v1*M1 x=e1*94601 # done with step 1 of CRT, doing one check. x % na M2 = N/nb M2 % nb Mod(186178^-1,nb) v2=533381 e2=v2*M2 x = x + e2*rb x % na x % nb M3 = N/nc Mod(M3^-1,nc) v3=251980 e3=v3*M3 x=x+e3*rc x x%na x%nb x%nc x%N 19951021419848000^(1/3) #This is how you could have gotten the whole computation in one line. crt([ra,rb,rc],[na,nb,nc]) # # The folloiwnng is a full XGCD computation to obtainn v3 M3 M3 % nc # I will use two vectos [r0,,a0,b0] and {r1,a1,b1] and swap between them # rather than always having r0 be the largeer of the two. r0 =nc a0 =1 b0=0 r1=298848 a1=0 b1=1 nc r0-r1 r0=r0-r1 a0=a0-a1 b0=b0-b1 # check what multiple fits r0 r1 r1=r1-r0 a1=a1-a0 b1=b1-b0 r1 r0 = r0=2*r1 r0 = 200305 r1 = 98543 r0 = r0 -2*r1 a0 = a0 -2*a1 b0 = b0 -2*b1 r0 r1 # the following is a rational number; multipy by 1.0 to get a decimal represenation r1/r0 r1*1.0/r0 r1 = r1-30*r0 a1 = a1-30*a0 b1 = b1-30*b0 r1 r0 = r0-r1 a0 = a0-a1 b0 = b0-b1 r0 r1=r1-r0 a1=a1-a0 b1=b1-b0 r1 r0 = r0-r1 a0 = a0-a1 b0 = b0-b1 r0 r1=r1-r0 a1=a1-a0 b1=b1-b0 r1 r0=r0-2*r1 a0=a0-2*a1 b0=b0-2*b1 r0 r1=r1-2*r0 a1=a1-2*a0 b1=b1-2*b0 r1 r0 = r0-51*r1 a0 = a0-51*a1 b0 = b0-51*b1 # we have r0 = a0 * nc + b0 *M3, so b0 is the inverse of M3 b0 v3 # note that XGCD can return negative numbers, so compute a positive representative mod nc b0+nc #for comparison Mod(M3^-1,nc)