package com.ejpm.euler.problem.impl;

import com.ejpm.euler.problem.Problem;
 

	/**
	 * The sequence of triangle numbers is generated by adding the natural numbers.
	 * So the 7^(th) triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28.
	 * The first ten terms would be:
	 * 		1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
	 * 
	 * Let us list the factors of the first seven triangle numbers:

     		1: 1
     		3: 1,3
     		6: 1,2,3,6
    		10: 1,2,5,10
    		15: 1,3,5,15
    		21: 1,3,7,21
    		28: 1,2,4,7,14,28
    		
	 * We can see that 28 is the first triangle number to have over five divisors.
	 * What is the value of the first triangle number to have over five hundred divisors?
	 */
public class Problem12 implements Problem {
	public static long triangle(long count){
		long result = 0;
		for(long i = 1; i <= count; i++){
			result += i;
		}
		return result;
	}
	
	public static boolean hasDivisors(long l){
		long contador = 0;
		
		for(long i = 1; i <= l; i++){
			if(l % i == 0)
				contador ++;
		}
		return contador >= 100;
		
	}
    @Override
    public void execute() {
		long maior = 0;
		long count = 1;
		
		while(maior == 0){
			long a = triangle(count);
			System.out.println(a);
			if(hasDivisors(a))
				maior = a;
			
			count ++;
		}
		
		System.out.println("Problem12 Maior: "+maior);
		maior = (long) Math.pow(maior,5);
		System.out.println("Problem12 Maior: "+maior);
     }
 
}

@@ -31,16 +31,138 @@
 .impl;%0A%0A
+import com.ejpm.euler.math.factorization.SimpleFactorizer;%0Aimport com.ejpm.euler.math.sequences.TriangularNumberSequence;%0A
 import c
@@ -198,15 +198,12 @@
 ;%0A %0A
-%0A%09
 /**%0A
-%09
  * T
@@ -278,17 +278,16 @@
 umbers.%0A
-%09
  * So th
@@ -352,17 +352,16 @@
 7 = 28.%0A
-%09
  * The f
@@ -385,17 +385,16 @@
 uld be:%0A
-%09
  * %09%091, 
@@ -435,14 +435,12 @@
 ...%0A
-%09
  * %0A
-%09
  * L
@@ -499,24 +499,20 @@
 umbers:%0A
-%0A
     
- %09%09
 1: 1%0A   
@@ -512,19 +512,16 @@
 : 1%0A    
- %09%09
 3: 1,3%0A 
@@ -523,19 +523,16 @@
 1,3%0A    
- %09%09
 6: 1,2,3
@@ -538,18 +538,16 @@
 3,6%0A    
-%09%09
 10: 1,2,
@@ -555,18 +555,16 @@
 ,10%0A    
-%09%09
 15: 1,3,
@@ -572,18 +572,16 @@
 ,15%0A    
-%09%09
 21: 1,3,
@@ -589,18 +589,16 @@
 ,21%0A    
-%09%09
 28: 1,2,
@@ -611,20 +611,17 @@
 ,28%0A    
-%09%09%0A%09
+%0A
  * We ca
@@ -691,17 +691,16 @@
 visors.%0A
-%09
  * What 
@@ -781,10 +781,8 @@
 rs?%0A
-%09 
 */%0Ap
@@ -828,677 +828,649 @@
 m %7B%0A
-%09public static long triangle(long count)%7B%0A%09%09long result = 0;%0A%09%09for(long i = 1; i %3C= count; i++)%7B%0A%09%09%09result += i;%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%09%0A%09public static boolean hasDivisors(long l)%7B%0A%09%09long contador = 0;%0A%09%09%0A%09%09for(long i = 1; i %3C= l; i++)%7B%0A%09%09%09if(l %25 i == 0)%0A%09%09%09%09contador ++;%0A%09%09%7D%0A%09%09return contador %3E= 100;%0A%09%09%0A%09%7D%0A    @Override%0A    public void execute() %7B%0A%09%09long maior = 0;%0A%09%09long count = 1;%0A%09%09%0A%09%09while(maior == 0)%7B%0A%09%09%09long a = triangle(count);%0A%09%09%09System.out.println(a);%0A%09%09%09if(hasDivisors(a))%0A%09%09%09%09mai
+        %0A    @Override%0A    public void execute() %7B%0A        System.out.println(%22Problem12:%5Ct The value of the first triangule number to have over five hundred divisors is: %22 + getFirstTriangularNumberWithNDivisors(500));%0A     %7D%0A %0A    %0A    public long getFirstTriangularNumberWithNDivisors(final int n)%7B%0A        int i = 1;%0A        %0A        while(true)%7B%0A            final int triangular = new TriangularNumberSequence().getElement(i);%0A            final int quantityFact
 or
+s
  = 
-a;%0A%09%09%09%0A%09%09%09count ++;%0A%09%09%7D%0A%09%09%0A%09%09System.out.println(%22Problem12 Maior: %22+maior);%0A%09%09maior = (long) Math.pow(maior,5);%0A%09%09System.out.println(%22Problem12 Maior: %22+maior);%0A
+new SimpleFactorizer().getFactorsQuantity(triangular);%0A            if(quantityFactors %3E n)%7B%0A                return triangular;%0A            %7D%0A            i ++;%0A   
      %7D%0A 
 %0A%7D%0A
@@ -1466,11 +1466,15 @@
      %7D%0A 
+   %7D
 %0A%7D%0A

Fix Problem 12 to use improve factorizer