elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Java / [APORTE] numeros primos en: 2 Diciembre 2009, 19:36 pm
Muestra el total de numeros primos que existen entre o y n, en este caso n tiene el valor de 20,000,000 (20 millones)
el contador es a

Código:
public class Main {  
    public static void main(String[] args) {
        int a=0,b,c=20000000,d;
        long tiempoInicio = System.currentTimeMillis();
        for(d=2;d<=c;d++){
            for(b=2;(b*b<=d)&&(d%b!=0);b++){
            }
            if((b*b)>d)
                a++;               
        }
        long totalTiempo = System.currentTimeMillis() - tiempoInicio;
        System.out.println("Tiempo de ejecucion: " + totalTiempo + " milisegundos");
        System.out.print(a);
    }
}
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines