Advertisement
jtentor

Primos por Jurado

Aug 19th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1.  
  2. public class PrimosPorJurado {
  3.  
  4.     public static void main(String[] args) {
  5.         long tiempoInicio = System.currentTimeMillis();
  6.  
  7.         int num = 2, cont = 0, i = 0;
  8.         int[] vec = new int[10000];
  9.         System.out.println("Los primeros 10000 nĂºmeros primos son:");
  10.  
  11.         while (cont < 10000) {
  12.             if (Primo(num, vec, i)) {
  13.                 vec[i] = num;
  14.                 //System.out.println(vec[i]);
  15.                 cont++;
  16.                 i++;
  17.             }
  18.             num += 1;
  19.         }
  20.  
  21.         System.out.println();
  22.         long totalTiempo = System.currentTimeMillis() - tiempoInicio;
  23.         System.out.println("Tiempo: " + totalTiempo + " milisegundos.");
  24.     }
  25.  
  26.     public static boolean Primo(int num, int[] vec, int i) {
  27.         if (num == 2 || num == 3 || num == 5) {
  28.             return true;
  29.         } else {
  30.             for (int j = 0; j < i; j += 1) {
  31.                 if (num % vec[j] == 0) {
  32.                     return false;
  33.                 }
  34.             }
  35.         }
  36.         return true;
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement