Project Euler – Problem 12

Problem 12: What is the value of the first triangle number to have over five hundred divisors?


class runner
{
	public static int numOfDivisors(int n){
		int result = 0;
		
		for(int i = 1; i<= Math.floor(Math.sqrt(n));i++){
			if(n%i == 0){
				if(n/i == i) result ++;
				else result += 2;
			}
		}
		
		return result;
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		long time = System.currentTimeMillis();
		int i=1;int cur=0;
		while(true){
			cur += i;
			int divs = numOfDivisors(cur);
			System.out.println("doing "+cur+" divs:"+divs);	
			if(divs > 500){
				System.out.println(cur + " time: " + (System.currentTimeMillis() - time));
				break;
			}
			i++;
		}
	}
}