# ROZSZERZONY ALGORYTM EUKLIDESA def euklides(a,b): x = 0 ostx = 1 y = 1 osty = 0 while b: wspol = a/b a, b = b, a%b ostx, x = x, ostx-wspol*x last, y = y, osty-wspol*y return ostx from math import floor,sqrt # ALGORYTM MALYCH I DUZYCH KROKOW def shanks(a,b,n,z): # MALE KROKI mk = [] m = int(floor(sqrt(z)))+1 for j in range(m): mk.append([j,pow(a,j,n)]) print mk # drukowanie tabeli malych krokow # DUZE KROKI dk = pow((euklides(a,n) % n),m,n) y = b for i in range(m): for el in mk: if el[1] == y: return i*m+el[0] % z y = (y * dk) % n # OBLICZANIE 3 DLP POWSTALYCH Z REDUKCJI HELLMANA x1 = shanks(pow(5,3*1973,47353),pow(43783,3*1973,47353),47353, 8) x2 = shanks(pow(5,8*1973,47353),pow(43783,8*1973,47353),47353, 3) x3 = shanks(pow(5,3*8,47353),pow(43783,3*8,47353),47353, 1973) print 'x1 = ',x1,', x2 = ',x2,', x3 = ',x3 # CHINISKIE TWIERDZENIE O RESZTACH a1 = 47352/8 a2 = 47352/3 a3 = 47352/1973 y1 = euklides(a1,8) % 8 y2 = euklides(a2,3) % 3 y3 = euklides(a3,1973) % 1973 print 'y1 = ',y1,', y2 = ',y2,',y3 = ',y3 x = (x1*a1*y1 + x2*a2*y2 + x3*a3*y3) % (8*3*1973) print 'x=',x # SPRAWDZANIE WYNIKU if 233195 % 47353 != pow(5,x,47353): print 'Wynik niepoprawny'
Standard input is empty
[[0, 1], [1, 44076], [2, 36951]] [[0, 1], [1, 7446]] [[0, 1], [1, 11204], [2, 44166], [3, 44367], [4, 23427], [5, 45782], [6, 13832], [7, 34712], [8, 3059], [9, 36817], [10, 5685], [11, 4955], [12, 18104], [13, 24317], [14, 25859], [15, 18582], [16, 28940], [17, 17769], [18, 11864], [19, 4385], [20, 24479], [21, 41493], [22, 23171], [23, 18738], [24, 24703], [25, 41480], [26, 19578], [27, 12816], [28, 16168], [29, 21047], [30, 40001], [31, 22412], [32, 38442], [33, 28633], [34, 34910], [35, 43213], [36, 21380], [37, 30046], [38, 2907], [39, 38517], [40, 16579], [41, 32650], [42, 8675], [43, 26344], [44, 6927]] x1 = 4 , x2 = 2 , x3 = 132 y1 = 7 , y2 = 1 ,y3 = 1562 x= 31700