时间是216ms
import java.util.Date;
/**
* Created by Administrator on 2015/5/11.
*/
public class E12 {
// 计算低 x 个三角形数
public static int computeTri (int x)
{
int sum=0 ;
for (int i=0 ; i<=x; i++)
sum+=i;
return sum;
}
public static boolean has500 (int x)
{
boolean has500=false;
int count=0 ;
for (int i=1 ; i<=(int )Math.sqrt (x); i++)
{
if (x%i==0 )
count=count+2 ;
}
if (count>=500 )
has500=true;
return has500;
}
public static void main (String[] args) {
long startTime=System.currentTimeMillis ();
for (int i=1 ; i<=(int )Integer.MAX_VALUE ; i++)
{
int temp=computeTri (i);
if (has500 (temp))
{
System.out .println(temp);
break;
}
}
long endTime=System.currentTimeMillis ();
System.out .println(endTime-startTime+"ms" );
}
}