jueves, 27 de octubre de 2011

numeros humildes

Números humildes. Un numero cuyos factores son 2, 3, 4 o7 se denominan un numero humilde. La secuencia 1, 2,3,4,5,6,7,8,9,10,12,14,15,16 ...
import java.util.*;

public class Pro1 {
public static int PrimeFactor(int n) {
int nprimos, cont, r, i, sw = 0;
int[] Vec1 = new int[10];
int[] Vec2 = new int[10];

if (n < 2) {
   sw = 1;
  } else {
   nprimos = 0;
   while (n > 1) {
cont = 2;
while (cont <= n) {
     r = n / cont;
     if (r * cont == n) {
      if (nprimos == 0) {
       nprimos = 1;
       Vec1[1] = cont;
       Vec2[1] = 0;
      } else {
       if (cont > Vec1[nprimos]) {
nprimos = nprimos + 1;
Vec1[nprimos] = cont;
Vec2[nprimos] = 0;
}
}
Vec2[nprimos] = Vec2[nprimos] + 1;
n = r;
cont = n;
}
cont = cont + 1;
}
}
for (i = 1; i <= nprimos; i++) {// System.out.println("Factor :" +
// Vec1[i]+" , " +Vec2[i]+" veces");
if (Vec1[i] <= 7) {
sw = 1;
} else {
sw = 0;
}
}
}
return sw;
}

public static void main(String[] args) {
int c = 1, h = 0, n, sw, print = 0;
Scanner in = new Scanner(System.in);
n = in.nextInt();
while (h < n) {
sw = PrimeFactor(c);

if (sw == 1) {
System.out.print(c + ", ");
h = h + 1;
print = c;
c = c + 1;
} else {
c = c + 1;
}
}
System.out.print(print);
}
}

0 comentarios:

Publicar un comentario