sábado, 11 de febrero de 2012

problem-34 euler

public class problem34 
{

 public static void main(String[] args) { 
   int v []= new int[10];
   
  for (int i = 0; i <=9; i++) 
  {
      v[i]= facto(i); 
  }
  int c =0;
  for (int i = 3; i < 100000; i++) 
  {
       if(check(i,v))
       {
        c= c+i;
       }   
  }
  System.out.println(c);
 }
 public static int facto(int n )
 {
  int f =1;
  for (int i = 1; i <=n; i++) 
  {
      f = f*i; 
  }
  return f;
 }
 public static boolean check(int n,int[]v)
 {
  String x = Integer.toString(n);
  int c =0;
  for (int i = 0; i < x.length(); i++) 
  {
         c= c+ (v[x.charAt(i)-48]);
  }
  if (c==n)
   return true;
  else
  return false;
 }
}

No hay comentarios:

Publicar un comentario