Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Complexity problem

I'm trying solve a problem which I have been able to code on a smaller scale though as soon as I start imputing larger values the time it takes increases considerably to the point where the final solution may take me a lifetime to find out.

The problem is Project Euler | Problem 12, I don't want the solution rather just guidance on a considerably more efficient collection type which may aid me.

The following is my own code:
```public class abc{
public static void main(String[] args){
for(int j=1;j<1000;j++){
List<Integer>ar = new ArrayList<Integer>();
for(int i=1;i<triangle(j)+1;i++){
if(triangle(j)%i==0){
}
}

if(ar.size()>5){
System.out.println(triangle(j));
break;
}
}
}

public static int triangle(int num){
if(num==1){
return 1;
}
return num +triangle(num-1);
}
}```
I need to replace the 5 with a 500 to find the solution.

2. ## Re: Complexity problem

Do only what is necessary to answer the question. Simplify your program to something like:

1. Find the next triangle number
2. Find the number of factors in the triangle number
3 Report the first triangle number to have over 500 factors and stop, OR
4. Goto 1

My solution is simpler than yours and could be simplified some, but finding the answer takes a looooong time.