[Solved] Java Program taking So much Long [closed]


Your problem is the sheer number of operations you’re doing. As I indicated in the comments, you’re doing over 500 million operations in the first 3 lines of main alone.

I also used trace statements to find out how many operations you were performing in the second half of this (I dumbly named the total number of operations s):

long s = 1;
        for (long i = 1; i < 32; i++)
        {
            s = 1;
            long powVal = (long)Math.Pow(4, i);

            Trace.TraceInformation("powVal: " + powVal);

            for (int n = 2; n < powVal; n++)
            {
                // Each call to streak could entail 1000 operations
                s *= 1000;
                Trace.TraceInformation("s: " + s.ToString());
            }
        }

Here are partial results:

VB Parser.vshost.exe Information: 0 : powVal: 4
VB Parser.vshost.exe Information: 0 : s: 1000
VB Parser.vshost.exe Information: 0 : s: 1000000
VB Parser.vshost.exe Information: 0 : powVal: 16
VB Parser.vshost.exe Information: 0 : s: 1000
VB Parser.vshost.exe Information: 0 : s: 1000000
VB Parser.vshost.exe Information: 0 : s: 1000000000
VB Parser.vshost.exe Information: 0 : s: 1000000000000
VB Parser.vshost.exe Information: 0 : s: 1000000000000000
VB Parser.vshost.exe Information: 0 : s: 1000000000000000000
VB Parser.vshost.exe Information: 0 : s: 3875820019684212736
VB Parser.vshost.exe Information: 0 : s: 2003764205206896640

And that’s only a partial result. As you can see, you’re doing an astronomical number of calculations. You need to reduce that in order to make the performance manageable.

6

solved Java Program taking So much Long [closed]