@@ -0,0 +1,1110 @@
+# Para interpretar e executar o programa, basta digitar no Terminal do Linux : python tp1.py%0A# -*- coding: utf-8 -*-%0A%0Aimport math%0A%0Aprint '%5CnAlgebra A - 2015/2%5Cn%5CnTrabalho Pratico - Parte 1%5Cn%5CnAutor: Ronald Davi Rodrigues Pereira - 2015004437%5Cn%5CnM%C3%A9todo de Fermat para achar fatores de um n%C3%BAmero de Mersenne%5Cn%5Cn'%0A%0Ai = 0%0A%0Afor p in xrange(2, 258):%0A%09aux = 0%0A%09for j in xrange(2, p):%0A%09%09if p %25 j == 0:%0A%09%09%09aux += 1%0A%09if aux == 0:%0A%09%09print '-----------------------------------------%5Cnp = %25d%5Cn'%25p%0A%09%09limite_r = (math.sqrt(2**p)-1)/(2*p)%0A%09%09parada = int(limite_r)%0A%09%09aux_2 = 0%0A%09%09r = 0%0A%09%09while 1:%0A%09%09%09if r %3E parada and aux_2 == 0:%0A%09%09%09%09print 'p = %25d faz com que M(%25d)=%25d seja primo.%5Cn'%25(p,p,(2**p)-1)%0A%09%09%09if r %3E parada:%0A%09%09%09%09break%0A%09%09%09if aux_2 == 1:%0A%09%09%09%09print 'p = %25d faz com que M(%25d)=%25d NAO seja primo.%5Cn'%25(p,p,(2**p)-1)%0A%09%09%09%09break%0A%0A%09%09%09E = p%0A%09%09%09A = 2%0A%09%09%09P = 1%0A%09%09%09q = r * 2 * p + 1%0A%0A%09%09%09while 1:%0A%09%09%09%09if E == 0:%0A%09%09%09%09%09if P == 1:%0A%09%09%09%09%09%09print '2%5E%25d %C3%A9 equivalente a %25d (mod %25d)%5Cn'%25(p,P,q)%0A%09%09%09%09%09%09aux_2 = 1%0A%09%09%09%09%09break%0A%09%09%09%09else:%0A%09%09%09%09%09if E %25 2 == 1:%0A%09%09%09%09%09%09P = (A * P)%25q%0A%09%09%09%09%09%09E = (E - 1)/2%0A%09%09%09%09%09else:%0A%09%09%09%09%09%09E = E / 2%0A%09%09%09%09%09A = (A**2)%25q%0A%09%09%09r+=1%0A

Create fermat.py