def t2(m=173): a = "11111001111011000001001110100010011100000111011111110000110001101011110100100011011100110100011000010011011100111100101110011101110011110001001110101101110000100000011111010" n = stb(conv(str(2**m - 1), 2, 10)) a = stb(a) d = bts(power(a, n)) if d == '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111': print("Nice") else: print("Хорошая попытка")
def sqrONB(a): a = stb(a) tmp = [] tmp.append(a[-1]) for j in range(len(a) - 1): tmp.append(a[j]) return tmp
def power(a, n): tmp = [] n.reverse() for i in range(0, len(a)): tmp.append(1) for i in range(0, len(n)): if n[i] == 1: matr = multMatrix(tmp) tmp = mulONB(tmp, a, matr) a = stb(sqrONB(bts(a))) return tmp
def invONB(a): print('a = ', a) a = stb(a) n = stb(conv(str(len(a) - 1), 2, 10)) k = 1 print('k = ', k) b = a for i in range(1, len(n)): print(Fore.RED + 'i = ' + str(i) + Style.RESET_ALL) d = power(b, stb(conv(str(2**k), 2, 10))) print('b^2 = ' + bts(d)) b = mulONB(d, b, multMatrix(d)) print('b = b^2 * b = ' + bts(b)) k = 2 * k print('k = ', k) if n[i] == 1: b = stb(sqrONB(bts(b))) print('b^2 = ' + bts(b)) b = mulONB(b, a, multMatrix(b)) print('b = b^2 * a = ' + bts(b)) k = k + 1 print('k = ', k) return bts(stb(sqrONB(bts(b))))
def t1(): a = "11111001111011000001001110100010011100000111011111110000110001101011110100100011011100110100011000010011011100111100101110011101110011110001001110101101110000100000011111010" b = "11111001111011001101001110100010011100000111011111110000110001101011110100100011011100110100011000010011011100111100101110011101110011110001001110101101110000100000011111010" c = "11111001111011000101001110100010011100000111011111110000110001101011110100100011011100110100011000010011011100111100101110011101110011110001001110101101110000100000011111010" tmp = Num() summ = tmp.addBig(stb(a), stb(b)) matrSumm = multMatrix(summ) res1 = mulONB(summ, stb(c), matrSumm) matrA = multMatrix(a) m1 = mulONB(stb(a), stb(c), matrA) matrB = multMatrix(b) m2 = mulONB(stb(b), stb(c), matrB) res2 = tmp.addBig(m1, m2) if res1 == res2: print("Nice") else: print("Nice try")
def Power(a, n): s = time.time() res = bts(power(stb(a), stb(n))) print(res + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL)
def Trace(a): s = time.time() res = bts(tr(stb(a))) print(res + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL)
def Mul(a, b): s = time.time() res = bts(mulONB(stb(a), stb(b), multMatrix(a))) print(res + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL)
def Add(a, b): tmp = Num() s = time.time() res = tmp.addPol(stb(a), stb(b)) print(res + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL)