"""Programa Creado Por Marcos Ochoa Diez Para Symbian Para Calcular Números Primos En Python Dando Rafagas De Luz Cuando Un Primo Sea Encontrado Dentro Del Intervalo Que Nosotros Previamente Le Digamos Que Calcule...""" import math, time import appuifw import e32 import thread, miso import graphics from random import randint appuifw.app.title=u"^MvIiIaX^ PrimosFlash" appuifw.note(u"Bienvenid@ Al Programa ^MvIiIaX^ PrimosFlash. 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 lighton(): while wanadoo: miso.reset_inactivity_time() e32.ao_sleep(5) 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 else: return False ole=0 restita=0 tardara=0 chupa=0 for mm in xrange(3,46350,2): if is_prime2( mm ): vector[ole]=mm ole +=1 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: ") ) luzbp=int( _raw_input("1-Luz Prima Blanca 2-Aleatoria ") ) luz=int( _raw_input("Luz Siempre Encendida 1-SI 2-NO: ") ) if int(luz)==1: wanadoo=1 thread.start_new_thread(lighton, ()) app=appuifw.app app.screen='full' c = appuifw.Canvas() appuifw.app.body=c draw = graphics.Draw(c) c.rectangle((0,0,176,208), fill = 0x000000) start_t = time.time() color=(randint(0,255),randint(0,255),randint(0,255)) if j < 2: if luzbp==1: c.rectangle((0,0,176,208), fill = 0xffffff) else: color=(randint(0,255),randint(0,255),randint(0,255)) c.rectangle((0,0,176,208), fill = color) color=(randint(0,255),randint(0,255),randint(0,255)) c.text([25, 190-5], unicode("N Primo. "+str(2),'iso-8859-1') , color) c.rectangle((0,0,176,208), fill = 0x000000) cuenta = 0 p=0 if j < 2: cuenta=1 if j==1: j=3 for j in xrange(j,limite+1,2): e32.ao_yield() if is_prime( j ): e32.ao_yield() if luzbp==1: c.rectangle((0,0,176,208), fill = 0xffffff) else: color=(randint(0,255),randint(0,255),randint(0,255)) c.rectangle((0,0,176,208), fill = color) color=(randint(0,255),randint(0,255),randint(0,255)) c.text([25, 190-5], unicode("N Primo. "+str(j),'iso-8859-1') , color) cuenta += 1 e32.ao_sleep(0.1) c.rectangle((0,0,176,208), fill = 0x000000) else: c.rectangle((0,0,176,208), fill = 0x000000) e32.ao_sleep(0.1) restita=time.time()-start_t print "\n" print restita, "... Segundos Procesando ...\n" print tiempo(int(restita)), "... Horas, Minutos Y Segundos De Proceso ...\n" if restita<1: restita=1 print "%d Primos Por Segundo Calculados\n" % int(cuenta/(restita)) print cuenta, "... Numeros Primos Desde ",inicio," Hasta ",limite," ..." appuifw.note(u"Todos Los Cálculos Han Sido Realizados Correctamente :)", "info" )