Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PrimosPorJurado {
- public static void main(String[] args) {
- long tiempoInicio = System.currentTimeMillis();
- int num = 2, cont = 0, i = 0;
- int[] vec = new int[10000];
- System.out.println("Los primeros 10000 números primos son:");
- while (cont < 10000) {
- if (Primo(num, vec, i)) {
- vec[i] = num;
- //System.out.println(vec[i]);
- cont++;
- i++;
- }
- num += 1;
- }
- System.out.println();
- long totalTiempo = System.currentTimeMillis() - tiempoInicio;
- System.out.println("Tiempo: " + totalTiempo + " milisegundos.");
- }
- public static boolean Primo(int num, int[] vec, int i) {
- if (num == 2 || num == 3 || num == 5) {
- return true;
- } else {
- for (int j = 0; j < i; j += 1) {
- if (num % vec[j] == 0) {
- return false;
- }
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement