This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def egcd(a, b): | |
| auxiliar = (a, b) | |
| a = max(auxiliar) | |
| b = min(auxiliar) | |
| x = (1, 0) | |
| y = (0, 1) | |
| while a % b != 0: | |
| q = a / b | |
| c = a % b | |
| nx = x[0] - (x[1] * q) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> chinese() | |
| 29246 | |
| >>> a = [4, 5, 6, 7, 8, 9] | |
| >>> m = [2, 3, 5, 7, 11, 13] | |
| >>> x = 29246 | |
| >>> for i in xrange(0, len(a)): | |
| if (a[i] - x) % m[i] == 0: | |
| print "{} es congruente con {} modulo {}".format(a[i], x, m[i]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> expmod(33, 93, 97) | |
| 64 | |
| >>> pow(33, 93, 97) | |
| 64 | |
| >>> expmod(12822, 1498, 997) | |
| 313 | |
| >>> pow(12822, 1498, 997) | |
| 313 | |
| >>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def expmod(a, b, n): | |
| rexpo = 1 | |
| pot = a % n | |
| while b > 0: | |
| if b % 2 == 1: | |
| rexpo = (rexpo * pot) % n | |
| b = b / 2 | |
| pot = (pot * pot) % n | |
| return rexpo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> gcd(765, 4321) | |
| son relativamente primos | |
| >>> gcd(765, 4323) | |
| no son relativamente primos | |
| >>> gcd(765, 4324) | |
| son relativamente primos | |
| >>> gcd(765, 4325) | |
| no son relativamente primos | |
| >>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gcd(a, b): | |
| auxiliar = (a, b) | |
| a = max(auxiliar) | |
| b = min(auxiliar) | |
| while a % b != 0: | |
| c = a % b | |
| a = b | |
| b = c | |
| resultado = b | |
| if resultado == 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> egcd(765, 4321) | |
| (1, 91, -514) | |
| >>> 4321 * (91) + 765 * (-514) | |
| 1 | |
| >>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def egcd(a, b): | |
| auxiliar = (a, b) | |
| a = max(auxiliar) | |
| b = min(auxiliar) | |
| x = (1, 0) | |
| y = (0, 1) | |
| while a % b != 0: | |
| q = a / b | |
| c = a % b | |
| nx = x[0] - (x[1] * q) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> for i in xrange(1, 51): | |
| resultado = factorizar(i) | |
| print str(i) + ' - ' + str(resultado) | |
| 1 - [1] | |
| 2 - [2] | |
| 3 - [3] | |
| 4 - [2, 2] | |
| 5 - [5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def factorizar(n): | |
| factores = [] | |
| if n > 1: | |
| for i in xrange(2, n + 1): | |
| while n % i == 0: | |
| n = n / i | |
| factores.append(i) | |
| if n == 1: |