Here\'s my code and it runs well with values of 400 to 4000 but once it\'s about 4mil, I get stack overflow errors.
Thanks in advance!
public class F
You can increase the stack size of Java programs. Example:
java -Xss4m YourProgram
Reference
Nevertheless I would also recommend an iterative method.