5 / 5
Jun 2010

I cant quite figure out how the code is expected to take input exactly, what is wrong with this code portion.. (this is the only parts that take input)

as far as i can test it it works fine with the input on my compiler.

After lots of trial and error, i found out that this NZEC error is not caused by the userinput part...

but it is caused when i call a method from my main method.

Any idea? or can someone give me elaboration on what exactly NZEC means so i can possibly find solution?

calcPrimes(cases);

private static int[] calcPrimes(int upperBound)
{
int bound = upperBound;
primes = new int[bound];
for(int i=0;i<bound;++i)
{
    primes[i]=i+1;
}
{
    int j=2;
    //eratheosthese?? sieve
while(j<=Math.sqrt(bound))
{
    for(int i=j+1;i<bound;++i) //j+1 because of the array starting at 0
    {
        if(primes[i]%j==0)
        {
            primes[i]=0;
           
        }
    
    }
    ++j;
}


int[] temp = new int[bound-countNonzero(primes)];
j=0;
for(int i=0;i<bound;++i)
{
    if(primes[i] != 0)
    {
    temp[j] = primes[i];
    ++j;
    }
}
primes = temp;
}
return primes;
}

actually this solution produces the correct result though..in any case

only bug is that it includes 1 as a prime which is fine since i notice this.
open_mouth

I would rather think about optimizing AFTER i even get it to submit properly

7 months later

If stack overflow in C++, and probably Java and other languages will throw an exception which results in Runtime Error NZEC at CodeChef.

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.