java中的高整除三角数:程序效率低下

java中的高整除三角数:程序效率低下,java,Java,我正在编写代码来计算第一个有500多个除数的数字,然而,由于效率低下,程序处理时间太长。这是我的密码: public class Lessons { public static void main(String[] args) { int a,b; int triangle=0; for (a=1;a>0;a++) { triangle += a; int cou

我正在编写代码来计算第一个有500多个除数的数字,然而,由于效率低下,程序处理时间太长。这是我的密码:

public class Lessons {


    public static void main(String[] args) {

        int a,b;
        int triangle=0;



        for (a=1;a>0;a++)
        {
           triangle += a;
           int count=0;

           for (b=1;b<=triangle; b++)
           {    
                if (triangle%b==0)
               {    
                   count += 1;
                }
            }
        if (count > 500)
        {
            System.out.println("The number is " + triangle);
            break;
        }
     }
    }}
公共课{
公共静态void main(字符串[]args){
INTA,b;
整数三角形=0;
对于(a=1;a>0;a++)
{
三角形+=a;
整数计数=0;
对于(b=1;b 500)
{
System.out.println(“数字为”+三角形);
打破
}
}
}}

有什么帮助吗?

当你的极限是
b当你的极限是
b时,我试着应用你的建议,但不知怎么的,它仍然没有加快速度。你能把修正后的代码贴出来吗???我试着应用你的建议,但不知怎么的,还是没能加快速度。你能把修改过的代码贴出来吗???
    public static void main(String[] args) {


    int number, limit, divisors;
    int i;
    Boolean found = false;

    number = 1;
    while (!found) {
        divisors = 0;
        limit = (int)Math.sqrt(number);
        i = 1;
        if (number % limit == 0) divisors++;
        while (i < limit) {
            if (number % i == 0) divisors +=2;
            i++;
        }
        if (divisors >= 500) {
            found = true;
            System.out.println("" + number);
        }
        number++;
    }
    System.out.println("done");
}