"""Programa Creado Por Marcos Ochoa Diez Para Symbian Para Calcular Números Primos En Python Grabando A Fichero Los Resultados""" import math, time import appuifw import e32 appuifw.app.title=u"^MvIiIaX^ Nº'S Primos II" appuifw.note(u"Bienvenid@ Al Programa De Cálculo De Nº's Primos Por ^MvIiIaX^. Espera Un Momento...", "info" ) vector= [0] * 4792 def _raw_input( txt ): return appuifw.query( unicode( txt ), "text" ) def tiempo(n): HOR=n/3600 MIN=(n /60)%60 SEG= n % 60 return (str(HOR)+":"+str(MIN)+":"+str(SEG)) def is_prime2( n ): j = int( round( math.sqrt( n ) ) ) for i in xrange(3, j+1, 2): if (n % i) == 0: return False return True def is_prime( n ): raiz = int( round( math.sqrt( n ) ) ) loco=0 while (n % vector[loco]!=0 and vector[loco]<=raiz):loco+=1 if vector[loco]>raiz: return True ole=0 restita=0 tardara=0 chupa=0 for mm in xrange(3,46350,2): if is_prime2( mm ): vector[ole]=mm ole +=1 f = open( "e:\\M8AX-S60-Primos.TxT", "w" ) f.write( "PROGRAMA CREADO POR M8AX PARA CALCULAR NUMEROS PRIMOS\n" ) f.write( "-----------------------------------------------------------\n" ) inicio = int( _raw_input("M8AX Dame El Numero De Comienzo: ") ) if (inicio%2)==0: inicio += 1 j = inicio limite = int( _raw_input("M8AX Dame El Numero Final: ") ) if j < 2: f.write( "%d\n" % 2 ) cuenta = 0 p=0 if j < 2: cuenta=1 if j==1: j=3 appuifw.app.screen = 'full' start_t = time.time() total = float( limite - j ) for j in xrange(j,limite+1,2): e32.ao_yield() chupa+=1 if is_prime( j ): f.write( "%d\n" % j ) cuenta += 1 p = ( ( j - inicio ) / total) * 100.0 if (cuenta % 400)==0: if chupa==0: chupa=1 restita=time.time()-start_t print "%2.f%% Completado\n" % ( p ) print "TMP. Transcurrido: ",tiempo(int(restita)) tardara=((((total)/2)*restita)/chupa)-restita print "\nTiempo +/- Para Fin: ",tiempo(int(tardara)) restita=time.time()-start_t print "\n%2.f%% Completado" % ( p ) print "\nTMP. Transcurrido: ",tiempo(int(restita)) if chupa==0: chupa=1 tardara=((((total)/2)*restita)/chupa)-restita print "\nTiempo +/- Para Fin: ",tiempo(int(tardara)) print "\n" print restita, "... Segundos Procesando ...\n" print tiempo(int(restita)), "... Horas, Minutos Y Segundos De Proceso ...\n" if restita<1: restita=1 f.write( "-----------------------------------------------------------" ) f.write( "\nSEGUNDOS EMPLEADOS EN EL CALCULO DE NUMEROS PRIMOS - " ) f.write ("%d" % int(time.time()-start_t)) f.write( "\nTIEMPO EMPLEADO EN EL CALCULO DE NUMEROS PRIMOS - " ) f.write (tiempo(int(restita))) print "%d Primos Por Segundo Calculados\n" % int(cuenta/(restita)) f.write( "\nPRIMOS POR SEGUNDO CALCULADOS EN EL INTERVALO DESDE %d HASTA %d - " % (inicio, limite )) f.write ("%d\r\n" % int(cuenta/(restita))) f.write( "NUMEROS PRIMOS CALCULADOS EN EL INTERVALO - " ) f.write ("%d\r\n" % cuenta) f.write( "-----------------------------------------------------------" ) print cuenta, "... Numeros Primos Desde ",inicio," Hasta ",limite," ..." f.write( "\nPROGRAMA CREADO POR M8AX PARA CALCULAR NUMEROS PRIMOS " ) f.write( "\n^MvIiIaX^ Corp 2006 " ) f.write( "\n-----------------------------------------------------------" ) f.close() appuifw.note(u"Todos Los Cálculos Han Sido Realizados Correctamente :)", "info" )